Running out of disk space can be annoying on your desktop system and potentially a disaster on your servers. To determine how much disk space is available and how much is currently in use, you can use the “df” command. To check how much space particular files and directories are consuming, use the “du” command.
The “df” command provides the “-h” options which output in a human-readable, usually in MB or GB.
This command display space on file systems in human-readable form
[root@Fedora11-vbox ~]# df -h
Filesystem Size Used Avail Use% Mounted on
6.7G 3.6G 2.9G 56% /
/dev/sda1 194M 21M 163M 12% /boot
tmpfs 250M 292K 250M 1% /dev/shm
If you have remote share mounted, these will show up too. So to limit the output to local systems only:
To check for disk space usage for particular files or directories in a file system:
[root@Fedora11-vbox ~]# du -h /home/
If you have root priviliges, you can use the “-s” option to get a summary of disk usage; otherwise, you will get “permission denied” when trying to access directories that you don’t have access to.
[root@Linux-box ~]# du -sh /home
You can also specify multiple directories with the “-c” option.
[root@Linux-box ~]# du -sch /home /var
You can specify how deep in the subdirectory tree you want to search. The “–max-depth” option let you set the depth of the search. In the following example with give “–max-depth” equals to “1” so the search will travel one level deep than the specified folder.
[root@Linux-box ~]# du --max-depth=1 /home