How to find the largest file in a directory and its subdirectories?

Quote from this link-

If you want to find and print the top 10 largest files names (not
directories) in a particular directory and its sub directories

$ find . -type f -printf '%s %p\n'|sort -nr|head

To restrict the search to the present directory use “-maxdepth 1” with
find.

$ find . -maxdepth 1 -printf '%s %p\n'|sort -nr|head

And to print the top 10 largest “files and directories”:

$ du -a . | sort -nr | head

** Use “head -n X” instead of the only “head” above to print the top X largest files (in all the above examples)

Leave a Comment