Here's a simple, one line script that finds all files roughly 2 megabytes in size in the filesystem's root directory.
find / -mount -size 2M -exec ls -l '{}' \; | awk '{print $5 " " $9}' > ~/files_2m.out
Let's break this down.
- -mount - This parameter says to ignore recursing through all mount points. Very handy if you want to ignore certain partitions. This is an all or nothing parameter.
- -size 2M - Finds files whose size is roughly 2Mb. The parameter will not search for anything significantly less or more than this size.
- -exec ls -l '{}' - This parameter executes the
ls -l command. The '{}' means to put the result as if running the ls -l command by itself. If you don't do it, it will just do a listing in the directory you're running the find command in!
- awk '{print $5 " " $9}' - Awk is another scripting language that's been around for a long time and is quite handy when parsing through text files. This line essentially prints columns 5 and 9 of the
ls -l output. In this case, it is the size and the filename and location of what find found.
- ~/files_2m.out - Stores the results of the
find in an output file.