In terminal, how can I find files that are bigger or smaller than x bytes? I suppose I can do something like "find . -exec ls -l {} \;" then pipe the result to awk to filter by file size. But shouldn't there be an easier way than this? Thank you.
|
feedback
|
migrated from stackoverflow.com Oct 28 '10 at 23:25
This question came from our site for professional and enthusiast programmers.
|
Am I missing the obvious here? find . -type f -size +4096c the -size n[cwbkMG]
File uses n units of space. The following suffixes can be used:
`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)
The size does not count indirect blocks, but it does count
blocks in sparse files that are not actually allocated. Bear in
mind that the `%k' and `%b' format specifiers of -printf handle
sparse files differently. The `b' suffix always denotes
512-byte blocks and never 1 Kilobyte blocks, which is different
to the behaviour of -ls.
| |||||||||||||||||||||
feedback
|
|
Greater than 2000 bytes:
Less than 2000 bytes:
| |||||||
feedback
|
Prints all files that are lesser than or equal to 4096 bytes in size. Simply change the operator and number at the end of this one-liner to change the criteria. The | ||||
|
feedback
|
|
Awk really is quite easy for this sort of thing, here are some things you can do with it in relation to file size checking like you asked: List files greater than 200 bytes
List files less than 200 bytes and write list to file
List files of 0 bytes, record list to file and delete the empty files
| |||
|
feedback
|
