Check disk space on Unix operating system

Unix command to check disk space:

  1. df command – Shows the amount of disk space used and available on Unix file systems.
  2. du command – Display disk usage statistic for each directory on Unix server.

How to display Unix disk usage statistics

See disk usage for all files in the current directory. Run:
du -a
To get the disk usage of a directory tree and each of its subtrees for /home/vivek, enter:
du /home/vivek
However, it is possible to see outout 1024-byte blocks if you pass the -k switch, enter:
du -k /home/vivek
Want to see total disk usage of a directory tree? Try:
du -s /home/vivek

248088	/home/vivek

One can summarize disk usage for a specific directory as follows:
du -hs /home

1.4G	/home

Next let us show name and size of all py (Python) files in a specific directory. Also display grand total at the end:
du -ch /home/vivek/project/mgt1.2/*.py

Getting help about du command

Try running the following man command or see online man page here:
man du
whatis du

How to display free disk space info on Unix

Check disk space on Unix using df command

To view the amount of free space in the file system, try df command:
df

Want to show information about /jails/www/ file system in 1024-byte blocks format, run:
df -k /jails/www/

Filesystem      1024-blocks    Used       Avail Capacity  Mounted on
zroot/jails/www 10745194355 3152328 10742042027     0%    /jails/www

Similarly, to show information about /jails/www file system in MB blocks format, enter:
df -m /jails/www/

Filesystem      1M-blocks Used    Avail Capacity  Mounted on
zroot/jails/www  10493353 3078 10490275     0%    /jails/www

How about GB blocks format for /jails/www file system?, Try:
df -g /jails/www/

Filesystem      1G-blocks Used Avail Capacity  Mounted on
zroot/jails/www     10247    3 10244     0%    /jails/www

Display a grand total

Pass the -c option:
df -c
Some version of Unix operating systems can display output in human readable format. In other words, Use unit suffixes: Byte, Kibibyte, Mebibyte, Gibibyte, Tebibyte and Pebibyte:
df -H
Sample outputs:

Filesystem Size Used Avail Capacity Mounted on zroot/ROOT/default 11T 4.2G 11T 0% / devfs 1.0k 1.0k 0B 100% /dev fdescfs 1.0k 1.0k 0B 100% /dev/fd zroot/iocage 11T 148k 11T 0% /iocage zroot/iocage/download 11T 131k 11T 0% /iocage/download zroot/iocage/download/11.2-RELEASE 11T 285M 11T 0% /iocage/download/11.2-RELEASE zroot/iocage/images 11T 131k 11T 0% /iocage/images zroot/iocage/jails 11T 131k 11T 0% /iocage/jails zroot/iocage/log 11T 131k 11T 0% /iocage/log zroot/iocage/releases 11T 131k 11T 0% /iocage/releases zroot/iocage/releases/11.2-RELEASE 11T 131k 11T 0% /iocage/releases/11.2-RELEASE zroot/iocage/releases/11.2-RELEASE/root 11T 1.2G 11T 0% /iocage/releases/11.2-RELEASE/root zroot/iocage/templates 11T 131k 11T 0% /iocage/templates zroot/jails 11T 131k 11T 0% /jails zroot/jails/fullbasejail 11T 364M 11T 0% /jails/fullbasejail zroot/jails/rsnapshot 11T 209G 11T 2% /jails/rsnapshot zroot/jails/www 11T 3.2G 11T 0% /jails/www zroot/tmp 11T 131k 11T 0% /tmp zroot/usr/home 11T 220k 11T 0% /usr/home zroot/usr/ports 11T 1.0G 11T 0% /usr/ports zroot/usr/src 11T 1.7G 11T 0% /usr/src zroot/var/audit 11T 131k 11T 0% /var/audit zroot/var/crash 11T 131k 11T 0% /var/crash zroot/var/log 11T 4.2M 11T 0% /var/log zroot/var/mail 11T 131k 11T 0% /var/mail zroot/var/tmp 11T 131k 11T 0% /var/tmp zroot 11T 131k 11T 0% /zroot devfs 1.0k 1.0k 0B 100% /jails/rsnapshot/dev devfs 1.0k 1.0k 0B 100% /jails/www/dev

See df command man page here or by typing the following command for more info:
man df

Conclusion

You learned how to see free and used disk space as well as disk usage statistics on Unix systems.

Source :: https://couponscorpion.com/development/php-masterclass-for-beginners/

Leave a Reply

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