Skip to main content

Viewing used disk space

In the linux command line we often find the need to see the amount of space used in the app directories. Sometimes due to system failures or simply because we need to know how much storage is available for our running services.

The df and du commands will help us with this.

df -h

df this command shows the available space on the filesystems of the directories that are passed as arguments, if no argument is given it will show the available space of all mounted filesystems.

it is helpful to use it with the -h option which gives us the space in amounts we can easily read, like M (Megabytes) or G (Gigabytes).

If we want to know the information of the root, it looks like this

df -h /

df_example

du -h -d 1

"du" this command helps to visualize the amount of space used by directories, without any argument it will show you that information for the current directory you are in.

It is also helpful to use it with the -h option which stands for "human readable", it gives us the space in amounts we can easily read, like M (Megabytes) or G (Gigabytes).

Finally we have the d 1 parameter which causes only the information of a subdirectory within the directories found in the current location to be displayed. This is very useful when we want to know where or what space is being used on the server.

du -h -d 1 /usr

du-h-d.png

Final thoughts

Now with this information you could do a little inspection on the storage in the linux operating system, and be able to find that file or directory that is consuming all the space on the server.