This short blog post will show you a command that will let you find the ten biggest files or directories in linux and osx machines. I forget these commands every time I need to use them, so I have added a post to my blog to help me be able to find them quickly (I use this post about once a week!)

Find 10 largest files linux or osx

du -a / | sort -n -r | head -n 10

You can use the same command to find the ten biggest files or directories in linux in a specific location like this (eg for /var/www)

du -a /var/www | sort -n -r | head -n 10

And you can modify the command to return more than ten results like this (return the top 25 files in /var/www)

du -a /var/www | sort -n -r | head -n 25

What the various parts mean

The pipe character | sends the output from one program to another. This is the unix way.

du -a / – (disk usage) this command shows the disk usage statistics for all the files in /, one per line man du gives lots of options. du -h / is one that I use all the time to check disk usage (along with df -h)

sort -n -r – this command sorts output. -n sorts numbers in an ascending order (lowest to highest). -r reverses the order.

head -n 25 – this command takes the first 25 lines, outputs them and stops

Altogether the command is:

get the filesize of all files, one per line, sort them in descending order of their filesize, and output 25 of them.

Sources (I used the man pages from my mac, but the commands are identical on linux too):
man sort
man head
man du