du | find

|^^|

source: http://www.ixbrian.com/blog/?m=201406

A common task for system administrators is determining what has filled up a full filesystem.

#1 – du -sm ./* | sort -n

With this command, you first CD in to the filesystem that is full. You then run:

du -sm ./* | sort -n

#2 – Find based on size

You can use the “find” command to search a filesystem to find large files. I especially like the “-xdev” flag which tells find to not traverse in to directories that are not part of the filesystem you are searching on. This is especially useful when your “/” (root) filesystem fills up because if you do a “find” on “/” without -xdev it will search every filesystem on the system since they are mounted under “/”. But with “-xdev” it will only search what is actually in the “/” filesystem and skip everything else.

Find all files larger than 1 MB:

find /tmp -xdev -size +echo 1024*1024 | bcc -ls

Find all files larger than 40 MB:

find /tmp -xdev -size +echo 1024*1024*40 | bcc -ls

Find all files larger than 1 GB:

find /tmp -xdev -size +echo 1024*1024*1024 | bcc -ls

Note that I’m just doing simple math with “bc” to calculate the byte size. For example, if you wanted 500 MB it would be 1024*1024*500. If you wanted 50 GB it would be 1024*1024*1024*50.

#3 – Find based on modification date

You can also use “find” to show files recently modified. Here are some examples:

Find all files modified in the last 60 minutes (mmin is minutes):

find /tmp -xdev -mmin -60 -ls

Find all files modified in the last 5 days (mtime is days):

find /tmp -xdev -mtime -5 -ls

Post a comment with your favorite commands you use to find what’s filling up your filesystems.

eof