100 Useful Command-Line Utilities

by Oliver; 2014

51. df, du

df reports "file system disk space usage". This is the command you use to see how many much space you have left on your hard disk. The -h flag means "human readable," as usual. To see the space consumption on my mac, for instance:
$ df -h .
Filesystem      Size  Used Avail Use% Mounted on
/dev/disk0s3    596G  440G  157G  74% /
df shows you all of your mounted file systems. For example, if you're familiar with Amazon Web Services (AWS) jargon, df is the command you use to examine your mounted EBS volumes. They refer to it in the "Add a Volume to Your Instance" tutorial.

du is similar to df but it's for checking the sizes of individual directories. E.g.:
$ du -sh myfolder
284M    myfolder
If you wanted to check how much space each folder is using in your HOME directory, you could do:
$ cd
$ du -sh *
This will probably take a while. Also note that there's some rounding in the calculation of how much space folders and files occupy, so the numbers df and du return may not be exact.

Find all the files in the directory /my/dir in the gigabyte range:
$ du -sh /my/dir/* | awk '$1 ~ /G/'

<PREV   NEXT>