Linux Tips: 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 /home/ -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 /home/ -type f -size +512k -exec ls -lh {} \;
I have added here -lh to the ls output so it will actually show the files with their sizes in a nice human readable format. Similar for smaller files you would use -size -512k.
Tags: tips
Share This







13th February 2008, 07:43
I’d highly recommend to avoid using -exec flag as it’s processing only one file per moment of time and can severely slow down the whole process of finding files (especially if you’re looking for sufficient number of them). It’s better practice to use “|xargs ls -lh” instead. xargs is really powerful tool - I suppose you won’t deny this. Sorry for my English once more
14th February 2008, 21:47
Pavel: you are right! Thank you for your note.
28th February 2008, 23:56
[...] more … Posted by sikor Filed in Blogroll [...]
29th February 2008, 01:09
[...] more … [...]
4th April 2008, 02:29
[...] Here addthis_url = [...]