In Linux, you can check disk space using command line tool called df command. The df command stands for Disk File System. Using df command you can find disk space summary information like available and used disk space on Linux.
In this tutorial, we are going to teach you ten different df commands with practical examples to manage disk space on Linux.
Let’s explore df command with all the options so that you will get complete idea on Linux disk space.
The basic syntax for df command is:
df [options] [devices]
1. Checking File System Disk Space
The “df” command displays the information of file system device names, disk blocks, total disk space used, available disk space, percentage of usage and mount points on a file system.
You could see a similar output on your screen.
root@fwh:~# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 10179896 3579164 6060584 38% / none 4 0 4 0% /sys/fs/cgroup udev 1020812 4 1020808 1% /dev tmpfs 205016 336 204680 1% /run none 5120 0 5120 0% /run/lock none 1025072 0 1025072 0% /run/shm none 102400 0 102400 0% /run/user
2. Display Disk Space in Human Readable Format
As you see in the first example, the output is difficult to read or understand. By default df command shows disk space information in bytes which is difficult to understand for humans. We can easily understand if the results are in megabytes and gigabytes.
Don’t worry, the good df command has an option to display information in human readable format like in MB and GB. You just need to add -h flag to see.
root@fwh:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 9.8G 3.5G 5.8G 38% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 997M 4.0K 997M 1% /dev tmpfs 201M 336K 200M 1% /run none 5.0M 0 5.0M 0% /run/lock none 1002M 0 1002M 0% /run/shm none 100M 0 100M 0% /run/user
3. Display information of all file systems
If you want to see all file systems including which has zero block sizes, pass parameter -a or -all along with df command. The output would be similar to this.
root@fwh:~# df -a Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 10179896 3579176 6060572 38% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys none 4 0 4 0% /sys/fs/cgroup none 0 0 0 - /sys/fs/fuse/connections none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security udev 1020812 4 1020808 1% /dev devpts 0 0 0 - /dev/pts tmpfs 205016 336 204680 1% /run none 5120 0 5120 0% /run/lock none 1025072 0 1025072 0% /run/shm none 102400 0 102400 0% /run/user none 0 0 0 - /sys/fs/pstore systemd 0 0 0 - /sys/fs/cgroup/systemd
4. Display File System details in Bytes
To display all file system information and usage in 1 K blocks , pass the option ‘-k‘ as follows.
root@fwh:~# df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 10179896 3579188 6060560 38% / none 4 0 4 0% /sys/fs/cgroup udev 1020812 4 1020808 1% /dev tmpfs 205016 336 204680 1% /run none 5120 0 5120 0% /run/lock none 1025072 0 1025072 0% /run/shm none 102400 0 102400 0% /run/user
5. Display File System Information in MB
To display all file system information and usage in MB or megabytes , pass the option ‘-m‘.
root@fwh:~# df -m Filesystem 1M-blocks Used Available Use% Mounted on /dev/sda1 9942 3496 5919 38% / none 1 0 1 0% /sys/fs/cgroup udev 997 1 997 1% /dev tmpfs 201 1 200 1% /run none 5 0 5 0% /run/lock none 1002 0 1002 0% /run/shm none 100 0 100 0% /run/user
6. Display File System Information in GB
To display all file system details and usage in GB or gigabytes , pass the option ‘-h‘.
root@fwh:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 9.8G 3.5G 5.8G 38% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 997M 4.0K 997M 1% /dev tmpfs 201M 336K 200M 1% /run none 5.0M 0 5.0M 0% /run/lock none 1002M 0 1002M 0% /run/shm none 100M 0 100M 0% /run/user
7. Display /home file system information
You can see only /home file system device infomation by executing below df command.
root@fwh:~# df -h /home Filesystem Size Used Avail Use% Mounted on /dev/sda1 9.8G 3.5G 5.8G 38% /
8. Display File System Type in Linux
To see the type of each file system pass the -T option. It gives output with file system types column. You could see the type of each file system listed such as ext4, ext3, tempfs, devtmpfs and etc.
root@fwh:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/sda1 ext4 10179896 3579192 6060556 38% / none tmpfs 4 0 4 0% /sys/fs/cgroup udev devtmpfs 1020812 4 1020808 1% /dev tmpfs tmpfs 205016 336 204680 1% /run none tmpfs 5120 0 5120 0% /run/lock none tmpfs 1025072 0 1025072 0% /run/shm none tmpfs 102400 0 102400 0% /run/user
9. Include or Exclude only certain File System Types.
If you want to see only ext4 file systems, use df command with option -t
root@fwh:~# df -t ext4 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 10179896 3579280 6060468 38% /
If you want to see all file system types except ext4, then pass -x option and type ( ext3, ext4) to exclude from the output.
root@fwh:~# df -x ext4 Filesystem 1K-blocks Used Available Use% Mounted on none 4 0 4 0% /sys/fs/cgroup udev 1020812 4 1020808 1% /dev tmpfs 205016 336 204680 1% /run none 5120 0 5120 0% /run/lock none 1025072 0 1025072 0% /run/shm none 102400 0 102400 0% /run/user
10. Display df Command Options and Help
You can see all the available options with df command by typing below command.
root@fwh:~# df --help Usage: df [OPTION]... [FILE]... Show information about the file system on which each FILE resides, or all file systems by default. Mandatory arguments to long options are mandatory for short options too. -a, --all include dummy file systems -B, --block-size=SIZE scale sizes by SIZE before printing them. E.g., '-BM' prints sizes in units of 1,048,576 bytes. See SIZE format below. --total produce a grand total -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) -H, --si likewise, but use powers of 1000 not 1024 -i, --inodes list inode information instead of block usage -k like --block-size=1K -l, --local limit listing to local file systems --no-sync do not invoke sync before getting usage info (default) --output[=FIELD_LIST] use the output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted. -P, --portability use the POSIX output format --sync invoke sync before getting usage info -t, --type=TYPE limit listing to file systems of type TYPE -T, --print-type print file system type -x, --exclude-type=TYPE limit listing to file systems not of type TYPE -v (ignored) --help display this help and exit --version output version information and exit Display values are in units of the first available SIZE from --block-size, and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set). SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000). FIELD_LIST is a comma-separated list of columns to be included. Valid field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent', 'size', 'used', 'avail', 'pcent' and 'target' (see info page).