Checking disk space is a crucial task in Linux system administration. Understanding how much storage is available or used on your system helps manage disk resources efficiently. With multiple disk partitions, filesystems, and mounted devices, knowing the available space can prevent problems like running out of disk space.
Linux provides several tools to monitor disk usage, allowing users to view details about their storage in various formats.
These commands give different perspectives on disk space. Some focus on the overall filesystem usage, while others provide detailed information about specific directories or devices. Some tools offer human-readable formats, making it easier to understand the space used or available.
Whether you’re managing a server, desktop, or embedded system, knowing how to check disk space is an essential skill for any Linux user.
1. df
The df
(disk free) command is the most commonly used tool to display the available and used disk space on all mounted filesystems. It shows the total size, used space, available space, and the mount point of each filesystem.
df -h
This command shows disk space usage in a human-readable format (e.g., GB, MB) instead of the default blocks. It displays the information for all mounted filesystems, including root (/
), home (/home
), and other partitions.
- -h : Human-readable format (converts bytes into KB, MB, GB)
2. du
The du
(disk usage) command estimates the disk space used by files and directories. It provides information about the space usage of specific files or directories, rather than the entire filesystem.
du -sh /home/user
This example shows the total disk space used by the /home/user
directory in a human-readable format. You can also use du
with other options to customize the output, such as displaying the size of each subdirectory inside the target directory.
- -s : Summarize the total disk usage of the directory (does not list subdirectories).
- -h : Human-readable format (KB, MB, GB).
3. lsblk
The lsblk
command lists information about all available block devices, including hard drives and partitions. It shows their sizes, types, and mount points.
lsblk
This command outputs a list of block devices, along with their sizes and mount points. It’s useful for checking which devices are mounted and their disk space usage.
4. free
The free
command shows memory usage and free space in your system, but it also provides disk space information when using it with the -h
option.
free -h
This command displays the system’s memory and swap usage in a human-readable format. Although it primarily shows RAM information, it can also provide disk space details for the swap area (used for virtual memory).
- -h : Human-readable format (KB, MB, GB).
5. fdisk
The fdisk
command is used to manage disk partitions, but it can also be used to view the size of disk partitions and their available space.
fdisk -l
This command lists all the partitions on your system, including their sizes, types, and other information. It’s especially useful for inspecting and managing partitions on hard drives and SSDs.
- -l : List all available partitions on the system.
Keeping track of disk space is an essential part of maintaining a healthy Linux system. Whether you’re managing storage for personal use or on a server, knowing how much space is available and used can help prevent system slowdowns and errors.
The commands we’ve discussed provide different ways to view and manage disk usage, each suited for specific needs. With these commands, you can ensure that your system runs smoothly and efficiently, avoiding potential issues caused by lack of storage.