7 Linux df Command Examples

by Himanshu Arora on May 21, 2012

df command in Linux provides disk space usage information of your file systems. Even if you already know about this command, probably one of the examples mentioned below might be new to you.

A sample output from df command is as follows:

$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1            132239776   6210884 119311504   5% /
tmpfs                  4021876         0   4021876   0% /dev/shm
/dev/sdb2             30969600    117740  29278696   1% /home/oracle
/dev/sdc1            576310180     71232 546964104   1% /home/data

So we see that df gives some valuable information on the file systems, their mount points, their memory usage etc.

1. Display Information of all the File Systems

If the disk usage of all the file systems is required then use ‘-a’ option:

$ df -a
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1            132239776   6210892 119311496   5% /
proc                         0         0         0   -  /proc
sysfs                        0         0         0   -  /sys
devpts                       0         0         0   -  /dev/pts
tmpfs                  4021876         0   4021876   0% /dev/shm
none                         0         0         0   -  /proc/sys/fs/binfmt_misc
/dev/sdb2             30969600    117740  29278696   1% /home/oracle
/dev/sdc1            576310180     71232 546964104   1% /home/data

So we see that in the output, details of all the file systems and their memory usage is there.

2. Specify the Memory Block Size

If you see the output in point 1 above, the second column gives the memory of file system in memory blocks of 1k. df command provides an option through which we can change the size of memory block in the output. Use option -B for this:

$ df -B 100
Filesystem         100B-blocks      Used Available Use% Mounted on
/dev/sda1            1354135307  63599535 1221749720   5% /
tmpfs                 41184011         0  41184011   0% /dev/shm
/dev/sdb2            317128704   1205658 299813848   1% /home/oracle
/dev/sdc1            5901416244    729416 5600912425   1% /home/data

So you see that we specified a block size of 100 and in the output (second column) block size of 100 is displayed.

3. Print Human Readable Sizes

We are used to reading the memory in terms of gigabytes, megabytes, etc as its easy to read and remember. df command also provides an option ‘-h’ to print the memory statistics in human readable format.

Option -h stands for “human” readable format. As shown in the output below, G is used for gigabytes and M is used for megabytes.

$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             127G  6.0G  114G   5% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sdb2              30G  115M   28G   1% /home/oracle
/dev/sdc1             550G   70M  522G   1% /home/data

4. Display Grand Total in the Output

Till now we have seen that only disk usage statistics of individual file systems is produced. If we want to display a grand total of every column then we can use the ‘–total’ flag. Here is an example:

$ df -h --total
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             127G  6.0G  114G   5% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sdb2              30G  115M   28G   1% /home/oracle
/dev/sdc1             550G   70M  522G   1% /home/data
total                 710G  6.2G  668G   1%

So we see that a new row ‘total’ at the end of the output was produced.

5. List Inodes (Instead of Block Usage)

Till now we have seen that df prints the second column as total memory blocks. If information in terms of inode is desired then df provides an option ‘-i’ for this.

$ df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda1            8396800   65397 8331403    1% /
tmpfs                1005469       1 1005468    1% /dev/shm
/dev/sdb2            1966560    2517 1964043    1% /home/oracle
/dev/sdc1            36593664      11 36593653    1% /home/data

So we see that information in terms of inodes is displayed.

6. Print File System Type

If you wish to print the type of file system in the output, use option ‘-T’.

$ df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext4   132239776   6210892 119311496   5% /
tmpfs        tmpfs     4021876         0   4021876   0% /dev/shm
/dev/sdb2     ext2    30969600    117740  29278696   1% /home/oracle
/dev/sdc1     ext2   576310180     71232 546964104   1% /home/data

In the above output, we can see all the file systems along with their type is displayed. Apart from using df -T to identify file system, there are 4 other methods to identify the file system types.

7. Include/Exclude Certain File System Type

You can also display file systems that belongs to certain type. For example, the following command displays only ext2 file systems. types.

$ df -t ext2
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sdb2             30969600    117740  29278696   1% /home/oracle
/dev/sdc1            576310180     71232 546964104   1% /home/data

You can also display file systems that doesn’t belongs to certain type. For example, the following command displays all other file systems except ext2. This is exactly opposite to the above -t option.

$ df -x ext2
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1            132239776   6210896 119311492   5% /
tmpfs                  4021876         0   4021876   0% /dev/shm

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 23 comments… read them below or add one }

1 kumarbka May 21, 2012 at 4:33 am

Nice info..

2 Jalal Hajigholamali May 21, 2012 at 6:45 am

Hi,
Thanks a lot
–total is not available on old “df” command

3 bob May 21, 2012 at 8:03 am

good job. thanks. I appreciate it when you expand out the meaning of the options. For example “df -h” and you explain that -h is for “human readable”. A lot of times we have difficulty remembering the option because we don’t remember what it stands for. Expanding the option helps us remember. This is something to keep in mind for your future columns.

4 J.O. May 21, 2012 at 8:06 am

df .

df followed by a dot reports which file system cwd is currently.

5 Bryan Sutherland May 21, 2012 at 10:52 am

Thanks for pointing out a couple of new flags to add to my df use. I wanted to add one of my top flags as well (-P) which forces POSIX compliant output and makes reading df output when using LVM much easier to read:
df -hP

6 sri May 21, 2012 at 11:23 am

thanx a lot…. its so helpful

7 Astorre May 21, 2012 at 5:33 pm

Always useful !!! :)

8 Mehdi Esmaeilian May 21, 2012 at 11:15 pm

Thanks,
It’s usefull.

9 Himanshu May 21, 2012 at 11:51 pm

Thank you all for your valuable comments!!

10 anonymous May 22, 2012 at 2:50 am

df – h –total is not displaying, what is version of df ?

11 Himanshu May 22, 2012 at 11:24 am

@anonymous
I am using version 7.4

12 Bryan Sutherland May 23, 2012 at 8:31 am

Anonymous, is there a space in your command? Also, can you tell me what distro and df version (df –version) you are using?

13 Vasudev May 24, 2012 at 9:36 pm

Thanx…. really useful to every one.

14 Aravindan May 25, 2012 at 7:47 pm

HI Anonymous, its :

  df -h --total 

you have left one hyphen(-).kindly check there will be 2 hyphen coming before total…

15 Fame May 29, 2012 at 3:31 am

df -h –total

You can’t use –total switch in RHEL/CentOS 4xx and RHEL/CentOS 5.xx.
I just tried , but you can definitely use in RHEL/CentOS 6.2.

( Which means you can’t use df’s switch “–total” in older version of coreutils-5.97-xxx . The core util found on CentOS 6.2 is coreutils-8.4-16.el6.x86_64. ).

16 Monali May 29, 2012 at 11:00 pm

Thanks a lot… It is very helpfull

17 Pascal June 3, 2012 at 3:18 am

If you want the output of df shown in a neat table use: df | column -t

To have all partitions sorted by percentage of used disk space (in increasing order) type:
df -Ph | sort -nk5
Options:
-n: sort by entire number not only the first digit, so 5% comes after say 1% and not 12%
-k5: sort using column 5 (in our case percentage of disk space used)

Hope that helps

18 israel June 7, 2012 at 7:57 am

Thank you very much for your realy valuable articles .

19 dhanda vijay August 20, 2012 at 6:53 am

superb jobs done by thegeekstuff

20 yunus September 12, 2012 at 12:40 am

Can anyone clarify why the df command does not show any output on my VPS (Centos 5.7)

21 Ashish Singhi August 19, 2013 at 11:58 pm

Thanks, helped a lot :)

22 Jakletti March 20, 2014 at 11:25 am

Hi,

I would like to know about df little bit internal.
when we execute command `df` on CLI, from where it will read the information.

23 Soham April 3, 2014 at 5:09 am

Hi,

The df -i command is not working in solaris. Please help.

Leave a Comment

Previous post:

Next post: