3 Ways to find the largest files in Linux

Updated: 19 hours ago

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


Using Du Command to Find the Largest Files

Find Largest Files and Directories under a specific directory and subdirectory

# 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.



Using ls Command to Find the Largest Files

ls -lSh /bin | head -5


Using Find Command to Find the Largest Files

find ./ -type f -exec du -sh {} \; |sort -h|tail -5


find / -size +100M -ls


find $DIRECTORY -type f -exec ls -s {} \; | sort -n | tail -n 5

Find File By Name in Linux

20 Advanced Linux Find Command Examples

How to use Find Command in Linux

3 Ways to find the largest files in Linux

10 Linux Find Exec examples - Advanced Part

84 views
udemylinux.png

Join our newsletter! Get a free cloud server!  Never miss a post!

Thanks for submitting!