10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

The Linux du (abbreviation of “Disk Usage”) is a standard Unix/Linux command which is used to check the disk usage of files and directories. The du command has many parameters that can be used to get the results in different choices.

The du command accepts different options which help to display results by date and time, highest or latest files and folders etc.

1. To find the disk usage summary of a /home/inimist folder tree its sub folders. Enter the command as:

2. Using -h option with du command shows results in “Human Readable Format“. it means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes etc.

3. To get the summary of a grand total disk usage size of an directory use the option -s as follows.

4. Using -a flag with du command displays the disk usage of all the files and directories.

5. Using -a flag along with -h displays disk usage of all files and folders in human readeable format. The below output is more easy to understand as it shows the files in Kilobytes, Megabytes etc.

6. The -k option is used to find out the aggregated disk usage of a directory and its subdirectories in Kilobytes. (1 Kilobyte = 1024 bytes).

7. Similarly -m flag counts the blocks size in MB units. -h option can be used to read size in Human readable format. For example, -mh or -kh as shown in previous example as well.

8. The -c flag aggregate the disk space size and puts grand total as the last line. If a directory took 540M space, then the last last two line of the output would be.

9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that matches given pattern. The below command excludes the “.txt” files while calculating the total size of diretory. So, this way you can exclude any file formats by using flag -–exclude. See the output there is no txt files entry.

10. Display the disk usage based on modification of time, use the flag –time as shown below.

Finding Largest files in a file system

Using sort and head option results are sorted recursively. By using head option along with n parameter number of results can be limited to a given number. This combination of commands can be very useful to find the largest files taking up space on your server.

Show largest file and directories sizes in linux

See how to find out largest files for more details on finding largest files on a linux machine.

Read also:

Leave a Reply