Linux df command - Disk Space Usage For Filesystems

May 9, 2013 | By
| Reply More

The df command reports the disk space usage for the filesystems. It displays various information such as total number of blocks in the filesystem, how many of these have been used and the number of available ones. This article explains various options of this command with examples.

df command options

Without any switch, df displays all mounted filesystems. The default output shows columns for following information: 'Filesystem', '1K-blocks', 'Used'(used blocks), 'Available'(blocks), 'use%'(the %age of used blocks againsta total number of blocks in a filesystem) and 'Mounted on'(the mount point of a filesystem).

$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6468104 3098980 68% /
udev 1521232 4 1521228 1% /dev
tmpfs 613188 1164 612024 1% /run
none 5120 0 5120 0% /run/lock
none 1532964 304 1532660 1% /run/shm
none 102400 8 102392 1% /run/user
/dev/sda8 5039616 2948248 1835368 62% /home
/dev/sda2 209715196 203404612 6310584 97% /media/raghu/Data

If a file name is provided as the argument to df command, the filesystem on which the file resides is displayed.

$ df file1.txt
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda8 5039616 2945900 1837716 62% /home

The name of one or more filesystems can also be provided as argument to display the particular filesystems:

$ df /dev/sda{7,8}
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6468104 3098980 68% /
/dev/sda8 5039616 2948336 1835280 62% /home

Producing the grand total

The --total option produces a grand total of all filesystems.

$ df --total
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6468104 3098980 68% /
udev 1521232 4 1521228 1% /dev
tmpfs 613188 1164 612024 1% /run
none 5120 0 5120 0% /run/lock
none 1532964 304 1532660 1% /run/shm
none 102400 8 102392 1% /run/user
/dev/sda8 5039616 2948336 1835280 62% /home
/dev/sda2 209715196 203407688 6307508 97% /media/raghu/Data
total 228608800 212825608 15015192 94%

(Note the last line saying total in the above output)

Including dummy filesystems

-a or --all option includes dummy filesystems (virtual fs like proc, sys etc).

$ df -a
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6468104 3098980 68% /
proc 0 0 0 - /proc
sysfs 0 0 0 - /sys
none 0 0 0 - /sys/fs/fuse/connections
none 0 0 0 - /sys/kernel/debug
none 0 0 0 - /sys/kernel/security
udev 1521232 4 1521228 1% /dev
devpts 0 0 0 - /dev/pts
tmpfs 613188 1164 612024 1% /run
none 5120 0 5120 0% /run/lock
none 1532964 304 1532660 1% /run/shm
none 102400 8 102392 1% /run/user
/dev/sda8 5039616 2948312 1835304 62% /home
/dev/sda2 209715196 203406664 6308532 97% /media/raghu/Data
binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc
gvfsd-fuse 0 0 0 - /run/user/raghu/gvfs

Human Readable Format

With -h options, instead of printing the number of blocks, the data is printed in MBs and GBs. The '1K-block' column is replaced with 'Size' column.

$ df -h /dev/sda{7,8}
Filesystem Size Used Avail Use% Mounted on
/dev/sda7 9.7G 6.2G 3.0G 68% /
/dev/sda8 4.9G 2.9G 1.8G 62% /home

The -H or --si option is similar to -h, but is uses powers of 1024 and not 1000(as with -h).

$ df -H /dev/sda{7,8}
Filesystem Size Used Avail Use% Mounted on
/dev/sda7 11G 6.7G 3.2G 68% /
/dev/sda8 5.2G 3.1G 1.9G 62% /home

The -B or --block-size=SIZE option can be used to provide custom format for sizes. SIZE may be (or may be an integer optionally followed by) one of following: KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

$ df -B2K /dev/sda{7,8}
Filesystem 2K-blocks Used Available Use% Mounted on
/dev/sda7 5039542 3234086 1549456 68% /
/dev/sda8 2519808 1474048 917760 62% /home

$ df -BM /dev/sda{7,8}
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/sda7 9843M 6317M 3027M 68% /
/dev/sda8 4922M 2879M 1793M 62% /home

The -k option is similar to --block-size=1k

$ df -k /dev/sda{7,8}
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6468172 3098912 68% /
/dev/sda8 5039616 2948128 1835488 62% /home

The -P option uses the POSIX output format

$ df -P /dev/sda{7,8}
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/sda7 10079084 6468172 3098912 68% /
/dev/sda8 5039616 2948128 1835488 62% /home

Printing inodes and filesystem type

The inodes can be printed with -i or --inodes option.

$ df -i /dev/sda{7,8}
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda7 640848 288304 352544 45% /
/dev/sda8 320000 50760 269240 16% /home

Here, total number of inodes, used, free and %age of used inodes are shown respectively.

If you want to print file system types as well, -T or --print-type switch is used

$ df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda7 ext4 10079084 6468168 3098916 68% /
udev devtmpfs 1521232 4 1521228 1% /dev
tmpfs tmpfs 613188 1164 612024 1% /run
none tmpfs 5120 0 5120 0% /run/lock
none tmpfs 1532964 304 1532660 1% /run/shm
none tmpfs 102400 8 102392 1% /run/user
/dev/sda8 ext4 5039616 2948128 1835488 62% /home
/dev/sda2 fuseblk 209715196 203427116 6288080 98% /media/raghu/Data

Now, suppose you want to print filesystems of a particular type, say ext4 only. The -t or --type=TYPE(ext4 here) option will do this for you.

$ df -t ext4
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6468168 3098916 68% /
/dev/sda8 5039616 2948128 1835488 62% /home

$ df -t tmpfs
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 613188 1164 612024 1% /run
none 5120 0 5120 0% /run/lock
none 1532964 304 1532660 1% /run/shm
none 102400 8 102392 1% /run/user

Similarly, for excluding a particular type of filesystem, use -x or --exclude-type=TYPE.

$ df -x tmpfs
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6468168 3098916 68% /
udev 1521232 4 1521228 1% /dev
/dev/sda8 5039616 2948164 1835452 62% /home
/dev/sda2 209715196 203433404 6281792 98% /media/raghu/Data

$ df -x ext4
Filesystem 1K-blocks Used Available Use% Mounted on
udev 1521232 4 1521228 1% /dev
tmpfs 613188 1164 612024 1% /run
none 5120 0 5120 0% /run/lock
none 1532964 304 1532660 1% /run/shm
none 102400 8 102392 1% /run/user
/dev/sda2 209715196 203433404 6281792 98% /media/raghu/Data

Limit listing to local filesystems only

By default, df command displays remote mounted filesystems as well. The -l option limits the listing to local filesystems only.

In order to check usage of this option, first we will mount a remote nfs filesystem.

$ sudo mount 192.168.1.14:/nfs nfs/

$ mount | tail -2
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw)
192.168.1.14:/nfs on /home/raghu/nfs type nfs (rw,vers=4,addr=192.168.1.14,clientaddr=192.168.1.6)

Now we execute the df command:

$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6533664 3033420 69% /
udev 1521232 4 1521228 1% /dev
tmpfs 613188 1172 612016 1% /run
none 5120 0 5120 0% /run/lock
none 1532964 304 1532660 1% /run/shm
none 102400 12 102388 1% /run/user
/dev/sda8 5039616 2948364 1835252 62% /home
/dev/sda2 209715196 203556460 6158736 98% /media/raghu/Data
192.168.1.14:/nfs 9547136 3640576 5421568 41% /home/raghu/nfs

And with -l option:

$ df -l
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda7 10079084 6533664 3033420 69% /
udev 1521232 4 1521228 1% /dev
tmpfs 613188 1172 612016 1% /run
none 5120 0 5120 0% /run/lock
none 1532964 304 1532660 1% /run/shm
none 102400 12 102388 1% /run/user
/dev/sda8 5039616 2948388 1835228 62% /home
/dev/sda2 209715196 203565068 6150128 98% /media/raghu/Data

Linux df command

Filed Under : LINUX COMMANDS

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.