Display Disk Utilisation

Displaying file and filesystem Utilisation with df and du commands.

df command - Reporting Filesystem disk space usage


The "df" command is used to display the amount of disk space available within a filesystem. If no parameters are passed to the "df" command, all filesystem information for currently mounted filesystems will be displayed. By default the disk space that is displayed is in 1K block sizes. If you supply a name of a filesystem to the "df" command, then only that information will be reported on. There are numerous parameters/options that can be passed.



df Command Examples


Example: df - No arguments passed



[john@centos ~]$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_centos-lv_root
                       6748936   3192592   3213512  50% /
tmpfs                   515368        80    515288   1% /dev/shm
/dev/sda1               495844     73013    397231  16% /boot
/dev/sdb1               287782     10287    262637   4% /test1
/dev/sdb2               295555     10287    270007   4% /test2
/dev/sdb3               295555     10287    270007   4% /test3
/dev/sdb5               295561     10287    270014   4% /test4
/dev/sdb6               295561     10287    270014   4% /test5
/dev/sdb7               295561     10287    270014   4% /test6
/dev/sdb8               264445     10287    240505   5% /test7
/dev/sr0               3626176   3626176         0
100% /media/CentOS_6.3_Final

Example: df - With total



[john@centos ~]$ df --total
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_centos-lv_root
                       6748936   3192076   3214028  50% /
tmpfs                   515368        80    515288   1% /dev/shm
/dev/sda1               495844     73013    397231  16% /boot
/dev/sdb1               287782     10287    262637   4% /test1
/dev/sdb2               295555     10287    270007   4% /test2
/dev/sdb3               295555     10287    270007   4% /test3
/dev/sdb5               295561     10287    270014   4% /test4
/dev/sdb6               295561     10287    270014   4% /test5
/dev/sdb7               295561     10287    270014   4% /test6
/dev/sdb8               264445     10287    240505   5% /test7
/dev/sr0               3626176   3626176         0
100% /media/CentOS_6.3_Final
total                 13416344   6963354   5979745  54%

Example: df - Human Readable



[john@centos ~]$ df --total -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
                      6.5G  3.1G  3.1G  50% /
tmpfs                 504M   80K  504M   1% /dev/shm
/dev/sda1             485M   72M  388M  16% /boot
/dev/sdb1             282M   11M  257M   4% /test1
/dev/sdb2             289M   11M  264M   4% /test2
/dev/sdb3             289M   11M  264M   4% /test3
/dev/sdb5             289M   11M  264M   4% /test4
/dev/sdb6             289M   11M  264M   4% /test5
/dev/sdb7             289M   11M  264M   4% /test6
/dev/sdb8             259M   11M  235M   5% /test7
/dev/sr0              3.5G  3.5G     0 100% /media/CentOS_6.3_Final
total                  13G  6.7G  5.8G  54%

Example: df - with specified name



[john@centos ~]$ df -h /test1
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1             282M   11M  257M   4% /test1

Example:df - Display filesystem type option



[john@centos ~]$ df --total -h -T
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
              ext4    6.5G  3.1G  3.1G  50% /
tmpfs        tmpfs    504M   84K  504M   1% /dev/shm
/dev/sda1     ext4    485M   72M  388M  16% /boot
/dev/sdb1     ext3    282M   11M  257M   4% /test1
/dev/sdb2     ext3    289M   11M  264M   4% /test2
/dev/sdb3     ext3    289M   11M  264M   4% /test3
/dev/sdb5     ext3    289M   11M  264M   4% /test4
/dev/sdb6     ext3    289M   11M  264M   4% /test5
/dev/sdb7     ext3    289M   11M  264M   4% /test6
/dev/sdb8     ext3    259M   11M  235M   5% /test7
/dev/sr0   iso9660    3.5G  3.5G     0 100% /media/CentOS_6.3_Final
total            -     13G  6.7G  5.8G  54%

df command options


Other arguments that can be passed to df



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)
  -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 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.


du command


The "du" command (Disk Usage) is used to report the size of directories and the contents within. This command is often used as a quick way of finding out what files are using taking most of your disk space.

Basic examples of du command:



[root@centos test1]# du /test1
12	/test1/lost+found
21	/test1

The above example display the size of the directory "/test1"



[root@centos test1]# du -h /test1
12K	/test1/lost+found
21K	/test1

The above is the same example, however, the "-h" flag is used to display the file sizes in a human readable format (K,M, G...)



[root@centos test1]# du -hs /test1
21K	/test1

john@john-desktop:~$ du -hs ~john 
53G	/home/john

The above examples display a summary of the directory "test1" and "/home/john"



[root@centos test1]# du -s *.txt
3	listing2.txt
3	listing3.txt
2	listing.txt

[root@centos test1]# du -hs *.txt
3.0K	listing2.txt
3.0K	listing3.txt
2.0K	listing.txt

The above examples display a summary of the files within the current directory that match the pattern "*.txt".


du command options



john@john-desktop:~$ du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarise disk usage of each FILE, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in (`sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -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.
  -b, --bytes           equivalent to `--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference only symlinks that are listed on the
                          command line
      --files0-from=F   summarise disk usage of the NUL-terminated file
                          names specified in file F;
                          If F is - then read names from standard input
  -H                    equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --si              like -h, but use powers of 1000 not 1024
  -k                    like --block-size=1K
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -L, --dereference     dereference all symbolic links
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -0, --null            end each output line with 0 byte rather than newline
  -S, --separate-dirs   do not include size of subdirectories
  -s, --summarize       display only a total for each argument
  -x, --one-file-system    skip directories on different file systems
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE
      --exclude=PATTERN    exclude files that match PATTERN
  -d, --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarise
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE  show times using style STYLE:
                          full-iso, long-iso, iso, +FORMAT
                          FORMAT is interpreted like `date'
      --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 DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

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.