Disk usage analysis

Taking care about disk usage is a very good habit. There are several options for this and now I will only describe df and du commands.

The df utility displays the disk space usage on all mounted filesystems.

[root@abc ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
                      35772016  20297132  13628408  60% /
/dev/sda1               101086     17692     78175  19% /boot
tmpfs                   513044         0    513044   0% /dev/shm

Adding the -T option (type) will print the filesystem type. Also, the good idea is to add -h option because df measures the size in 1K blocks, which is difficult for a desktop user to recalculate.

Now we have

[root@abc ~]# df -h -T
Filesystem    Type    Size  Used Avail Use% Mounted on
              ext3     35G   20G   13G  60% /
/dev/sda1     ext3     99M   18M   77M  19% /boot
tmpfs        tmpfs    502M     0  502M   0% /dev/shm

As you can see, it is much easier to understand.

You can use the du command to determine which files or directories need to be deleted or reduced. A simple du will print usage for the present working directory and its subdirectories, along with the size of each directory.

du directory will print the size of an particular dir.

Avilable options:
-h – print the size of the podcasts directory in a more readable format
-c – prints the grand total size of the directory at the end.
-a – displays the file names along with directories
-s – display a summary, without showing all of the subdirectories.

For example, du -ch | grep total prints just one line with the total size of the directory.

Leave a Reply

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