Linux command tips : df



This “Bash command tips” page is about the df command. This post is not supposed to be exhaustive, its only purpose is to show some tips regarding the df command; I will update this page each time i found something interesting.


Command information

  • Purpose : report file system disk space usage and/or freespace
  • Required privileges : user
  • Default path (RHel based distros) : /bin/df
  • Used version in this post : df (GNU coreutils) 5.97
  • Exit code : 0=Success, 1=Failure



1) df command generalities

df stands for “disk free”, which clearly indicate that it is devoted to disk space analysis. df usually uses the mtab file or statfs() routine.


2) df command general syntax

The general syntax for the df command is :

df <option> <file>

Called without any arguments df would print information about all filesystems which the invoking user has appropriate read access.


3) Get free space in an “easy-to-read” format (aka human readable)

Aka “make the df output really readable”. As for many other Linux command a human-readable option exists to display results in a more understandable way.

Note-h stands for human-readable

df -h

3.1 Example and output

[root@server ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
                      9.7G  4.5G  4.8G  49% /
                      9.7G  152M  9.1G   2% /tmp
                      124M   17M  101M  15% /Admin
                      2.0G   72M  1.8G   4% /var/log
                       50G   17G   31G  36% /Phases
/dev/sdb1             1.8T   31G  1.7T   2% /Seances
/dev/sda2             487M   31M  431M   7% /boot
tmpfs                 2.0G     0  2.0G   0% /dev/shm



4) Display the file system type

The df command can also provide you the type of file system : FAT, EXT3, NTFS etc… This is done using the -T option.

df -T

Note-T stands for Type-print

4.1 Example and output

As you can see an extra column (Type) is now showing the filesystem type :

root@server ~]# df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
              ext3    10157368   4643812   4989268  49% /
              ext3    10157368    154652   9478428   2% /tmp
              ext3      126931     17018    103360  15% /Admin
              ext3     2031440     72716   1853868   4% /var/log
              ext3    51831404  17228568  31969928  36% /Phases
/dev/sdb1     ext3   1922858352  31771044 1793411708   2% /Seances
/dev/sda2     ext3      497861     31380    440777   7% /boot
tmpfs        tmpfs     2018708         0   2018708   0% /dev/shm



5) Using df command within a shell script

In order to use the df command from within a script you will need it to format its output in a fixed format (you will, for sure, need to parse the df output), this can be done using the -P option.

df -P

Note-P stands for Posix-format

5.1 Example and output

[root@server ~]# df -hPT
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup_ID_18689-root_el5 ext3  9.7G  4.5G  4.8G  49% /
/dev/mapper/VolGroup_ID_18689-tmp_el5 ext3  9.7G  152M  9.1G   2% /tmp
/dev/mapper/VolGroup_ID_18689-Admin ext3  124M   17M  101M  15% /Admin
/dev/mapper/VolGroup_ID_18689-var_el5 ext3  2.0G   72M  1.8G   4% /var/log
/dev/mapper/VolGroup_ID_18689-Phases ext3   50G   17G   31G  36% /Phases
/dev/sdb1     ext3    1.8T   31G  1.7T   2% /Seances
/dev/sda2     ext3    487M   31M  431M   7% /boot
tmpfs        tmpfs    2.0G     0  2.0G   0% /dev/shm



6) Display informations only for a chosen file system type

You can choose the file system type you want informations for using the -t option. This could be useful for scripting or interactive shell use.

Note : The possible file systems are the same your OS can manage.

df -t <file_system_type>

Note-t stands for type

6.1 Example and output

[root@server ~]# df -hT -t tmpfs
Filesystem    Type    Size  Used Avail Use% Mounted on
tmpfs        tmpfs    2.0G     0  2.0G   0% /dev/shm



7) Filter file systems type checked by df

It is possible to exclude a given (multiple file systems may be specified by using multiple -x statement) file system from being processed by df.

df -x <file_system_type>

Note-x stands for exclude

7.1 Example and output

[root@server ~]# df -hT -x ext3
Sys. de fich. Type     Tail. Occ. Disp. %Occ. Monté sur
tmpfs        tmpfs    2,0G     0  2,0G   0% /dev/shm
               nfs    103G   23G   74G  24% /diskpat



8) Display informations for local file system only

In case you would only want to see space usage of your local file systems (excluding nfs, samba fs etc…), you may use the -l option.

df -l

Note-l stands for local

8.1 Example and output

[root@server ~]# df -hl
Sys. de fich.         Tail. Occ. Disp. %Occ. Monté sur
9,9G  3,9G  5,5G  42% /
2,0G   79M  1,8G   5% /var/log
/dev/sdb1             917G  782G   88G  90% /Phases
9,9G   56M  9,3G   1% /tmp
/dev/sda2             487M   31M  431M   7% /boot
tmpfs                 2,0G     0  2,0G   0% /dev/shm




More “Linux command tips” posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site supports SyntaxHighlighter via WP SyntaxHighlighter. It can highlight your code.
How to highlight your code: Paste your code in the comment form, select it and then click the language link button below. This will wrap your code in a <pre> tag and format it when submitted.