Search This Blog

2012-11-30

Disk Usage in *nix

This page will be handful of useful commands you can use to find disk statistics. I will start off with some simple ones and then later when I feel the need or get time will provide further ones.

Total Disk Usage

One of my favourite disk usage commands to find total disk usage on only mounted partitions is:

df -cl
-c - display the grand total
-l - only local partitions

I will be providing much more interesting command and information at a later point in time. Including visual space usage using some bash and shell scripts as well as the differences between df and du when it comes to tracking used disk space.

Note: df -c does not work in linux. I have not yet found a way to print out total local disk usage for this yet.

DF Not Updating Actual Disk Space

Sometimes when you delete a file it will not show the free space using the 'df' command. The reason being is that the file may still be held open by a process in which the file descriptor handles still point to the file.

To find these processes run the following commands:

lsof | grep 'deleted'
ls -ld /proc/* | grep '(deleted)'

The solution to updating the space shown by df is to kill the process so

kill $PID
kill -9 $PID

Alternatively I believe the 'du' does not experience the same issues when looking for free disk space.

As you can see, I get a summary of all the subdirectories as well as a grand total. This is very useful in figuring out what main directories are using up the majority of your space.

-s - summary of directories (only print the grand totals of each sub directory)
-c - print out a total of all of the queried subdirectories at the end
-h - human-readable (print out all directories in summaries of K,M,G instead of just printing in bytes) - might want to remove if you want to sort these properly

Additionally, you can ad a --max-depth=$number to this command to only go a certain depth into the subdirectories or even just specify specific directories in which you want to query like