Linux find largest file in directory recursively using find/du


Originally published at:

I have 500GB SSD installed on my Linux server. My web server is running out of the disk space. I need to find a biggest or largest file concerning file size on the disk. How do I find largest file in a directory recursively using the ?


First I tried

find . -type f | xargs du -a | sort -nr | head

but this doesn’t cleanly take care of filenames with spaces in them (sadly I have friends that use them)
the following is more awkward, but works

find . -type f -exec du -a ‘{}’ ; | sort -nr | head

on a big disk this may take a while. Replace “.” with the root directory if you don’t want the current directory.


Is the 500GB drive your only drive or part of a larger disk system?

sudo du -xak |sort -n

The command above is one I often relied on during my monitoring shifts.