Howto: Find All Files of a Particular Size

The Unix find command is a very powerful tool, and this short post is intended to show how easy you can achieve something that might look complicate: to find all the files of a particular size. Let’s assume you are searching for all the files of exactly 6579 bytes size inside the home directory. You will just have to run something like:

find /path/ -type f -size 6579c -exec ls '{}' +

As units you can use:

  • b – for 512-byte blocks (this is the default if no suffix is used)
  • c – for bytes
  • w – for two-byte words
  • k – for Kilobytes (units of 1024 bytes)
  • M – for Megabytes (units of 1048576 bytes)
  • G – for Gigabytes (units of 1073741824 bytes)

You can search for exact file size, or just for bigger (+) or smaller (–) files. For example all bigger than 512k files would be found with something like:

find /path/ -type f -size +512k -exec ls -lhSr '{}' +

I have added here -lSrh to the ls output so it will actually show the files with their sizes in a nice human readable format, -S to order by size and -r for smallest to biggest . Similar for smaller files you would use -size -512k.

To find files in sizes between two sized do as above but add an additional -size to the string with an upper value

find /path/ -type f -size +500M -size -600M -exec ls -lShr '{}' +

This find files bigger than (>) 500 Megabytes but smaller than (<) 600 Megabytes

Leave a Reply

Your email address will not be published. Required fields are marked *

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