search / find by size on Unix / Linux systems – Tip of the Week

Searching by size on *nix systems by using the find command may not be readily apparent.

Say you have a file system approaching 100% full (/var/log is an example which comes to mind), and you want to do some housekeeping.  You want to locate all files in /var/log which are larger than say 10Mbyte – here is the find command which will do this for you:

find /var/log -size +10000000c -ls

… this will locate all files larger than 10,000,000 characters, i.e. 10Mbytes, and will do a long ls listing, which will show the full path and size of each file.  In older Unix systems, the -ls command may not be an option to the find command, so you can use the -exec option instead:

find /var/log -size +10000000c -exec ls -lt {} \;

…which will do the same thing.  Let’s say you have your root file system nearly full, and also have a number of other file systems mounted under /.  How do you restrict your find command to only search under the root file system, and not the others?  Use the -xdev option, as follows:

find / -xdev -size +10000000c -exec ls -lt {} \;

..this will only search under / and will not cross file system boundaries to other mount points.

Advertisements

About Michael Abboud

Linux / Unix Technical Specialist
This entry was posted in Linux / Unix Tips and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s