Finding Large Files in Unix/Linux

17fd0-6a00e551c39e1c883401a3fd32be00970b-piBack in the day I used to have some really good notes on this topic, but alas they are long gone, so I have decided to put together a small list with some helpful examples.

Note that a lot of folks will show you examples where they pipe their find out to a ‘rm’ command. This is bad mo-jo in my opinion and should be avoided. Mass deleting files based on size alone is not a good practice. There are exceptions, but as a rule I avoid it like hoof and mouth disease.

Use this simple command to find large directories. To find directories over 1GB

[root@localhost]# du -h / | grep ^[0-9\.]*G

G can be replaced with M if looking for MB instead.

To find directories over 10GB and sort the output with the largest directories on top

[root@localhost]# du -h / | grep ^[1-9][0-9][0-9\.]*G | sort -rn

To find files within a size limit.

find /etc -size +100k -size -150k

Find files under /, and do not cross filesystems. This will keep you from searching pesky nfs and san mounts.

find / -name -depth +100k

Show directory sizes using du

 du -sk /usr/*

Find the largest 10 files

find / -size +15M -printf “%s – %p\n” | sort -n | tail

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.