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:
ducommand shows results in “Human Readable Format“. it means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes etc.
du -h /home/inimist
3. To get the summary of a grand total disk usage size of an directory use the option
du -sh /home/inimist
ducommand displays the disk usage of all the files and directories.
du -a /home/inimist
-aflag along with
-hdisplays 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.
du -ah /home/home
-koption is used to find out the aggregated disk usage of a directory and its subdirectories in Kilobytes. (1 Kilobyte = 1024 bytes).
du -k /home/inimist
-mflag counts the blocks size in MB units.
-hoption can be used to read size in Human readable format. For example,
-khas shown in previous example as well.
du -mh /home/inimist
-cflag 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.
du -ah --exclude="*.txt" /home/inimist
10. Display the disk usage based on modification of time, use the flag
–timeas shown below.
du -ha --time /home/inimist
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
du -hs /home/ | sort -rh | head -10
sudo du -ma /home/ | sort -n -r | head -n 20
find /home -type f -printf '%s %p\n' | sort -nr | head -20
sudo du -a /home/ | sort -n -r | head -n 20
See how to find out largest files for more details on finding largest files on a linux machine.
Hello Friends, I’m Arvind Kumar, founder of Inimist Technologies, Inimist Academy, The Fundabook and many more. I am a Full Stack Web Developer and Programmer by heart, and a Hindi/English blogger by chance. I build Web and Mobile Application around React, VueJS, NodeJS and PHP frameworks.
Have a project in mind? Get in touch