Linux Commands

How to Check Disk Usage in Linux

In Linux-type servers, it is essential to keep checking the disk usage information and managing it before causing any trouble. When you monitor the disk report on a daily basis, it helps to figure out which file or directory is consuming more disk space and which of them needs to be cleaned.

How to Check Disk Usage on Linux

Getting the disk information is quite handy when you’re working with a Linux system, and you have several command-line tools to check it. Let’s display the disk usage information using the following pre-installed Linux utilities:

  1. Linux df command
  2. Linux du command

You can also get the disk usage report on your screen through the graphical user interface method, so, this article will cover both of these approaches.

Check Linux Disk Usage Using the df Command

In Linux disk free or df command tool is used to print the disk information that includes the available disk space on Linux storage.

The given syntax would be followed to utilize the df command tool to find out the disk usage on Linux:

df [options…] [device_name…]

You can access the data on the terminal by running simply df command or utilizing it with the -h parameter to display in human-readable format:

df

Or:

df -h

The above output fields mean:

Filesystem Shows all the drives including, physical, virtual, partitioned, and temporary drives
Size Shows the filesystem’s size
Used Displays the size of used filesystem space
Avail Displays the available space on the filesystem
Use % Displays the used space in percentage
Mount on Displays the directory location where the filesystem is stored

Execute the mentioned command to print the disk usage of the file system, even if the available and used field is 0. This could be done by passing the -a argument with the -h (which helps to display out in human-readable format):

df -ha

If you also want to see the filesystem type while displaying the disk usage information, use the -T parameter with the df command; like:

df -T

To print the used and free index node (inode) against each filesystem, pass the -i argument:

df -i

Or you can use the -i argument with the -T to display the inode with the filesystem type:

To display the disk used and available for a specific filesystem’s type, the following syntax would be followed:

df -t [filesystem_type_name]

For example, to show only the tmpfs file type disk usage information, run the given command:

df -t tmpfs

And, to show the complete data except for any specific type, the -x argument would be passed, like:

df -xT ext4

Use the –o parameter to show all the fields while displaying the disk space usage information on the Linux terminal:

df --o

You can also check the complete filesystem and disk usage information by passing the -a or –all argument with the df command tool and this will present you with the whole disk report:

df --all

To get more help regarding the Linux df command tool, you can visit the man page or pass the –help parameter:

man df

Or:

df --help

Check Linux Disk Usage Using the du Command

Linux disk usage or du command-line tool helps to mention the disks or block usage reports in all files and directories. It also helps to identify which file or directory is consuming more space in the Linux system.

We can utilize the du command to find the disk usage information against each file and folder in the Ubuntu server:

du

Pass the -h argument with the du command to print the required result in human-readable format against files or directories. This will identify the disk size in kilobytes, megabytes, gigabytes etc.; run the given command to show how it works:

du -h

Run the du command with the -a parameter to display disk usage information against all files and directories:

du -a

To display the summarized disk usage information in the Linux server, use the -s parameter:

du -hs

To show the disk usage information for a particular filesystem, execute the given command with the file location:

du -s ./.ssh

Run the mentioned command to display the disk space usage report in human-readable format against the particular directory i-e, /etc/ (this requires sudo privileges to access all of the /etc/ files):

sudo du -h /etc/

You can also get the top 5 directories that occupy the most disk space in the Linux machine through the following command:

sudo du -a /etc/ | sort -n -r | head -n 5

To get more help regarding the Linux du command tool, you can visit the man page or pass the –help parameter:

man du

Or

du --help

Check Linux Disk Usage Using the GUI

Another way to get the disk usage report is through the GUI by typing Disks in the search box:

After opening the Disks app, you will get the drives on the Linux screen, click any of the partitions, and you will get its data report on the screen:

Conclusion

Checking the disk utilization is important as it helps to avoid space issues when installing anything. You can also clean when to figure out, which file or directory is consuming more disk space. Throughout this guide, we have mentioned the various approaches to finding disk usage in Linux servers. These approaches include the command-line tools and graphical user interface.

In the command-line tools, we have utilities like df and du that help to display the disk usage report on a Linux machine. Moreover, we have mentioned multiple arguments with these command-line tools to display output in different fields and formats.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.