Using Du to find the largest files and directories in Linux

Updated: Mar 22

We can use the following commands to find the largest files and directories in #Linux.


Find Largest Files and Directories under a specific directory and subdirectory in Linux

# du -ah /home | sort -n -r | head -n 5


Find Largest Files and Directories under the current working directory and subdirectory.

# du -ah | sort -n -r | head -n 5


Find Largest Directories or Files in the current working directory

# du -sh * | sort -rh | head -5


Find Largest Directories or Files in / directory

# du -ahx / | sort -rh | head -5


We use the following commands in our examples.

  • #du command : It estimates file space usage

  • sort command : Sort lines of text files or given input data

  • head command : Output the first part of files i.e. to display first 10 largest file

We use the following options in our examples.

  • #du command -h option : display file sizes in human-readable format, in Kilobytes, Megabytes and Gigabytes.

  • du command -s option : Show total for each argument.

  • du command -x option : Skip directories. (if on different file systems)

  • sort command -r option : Reverse the result of comparisons.

  • sort command -h option : Compare the numbers.

  • head command -10 OR -n 10 option : Displays the first 10 lines of the output.



76 views

Join our newsletter. Get a free Linux account on Cloud.

Get a Free Cloud Server! 

We can use this cloud server to practice Linux commands. Never miss a post!

Thanks for submitting!