Finding Files by Size
Problem
You want to do a little housecleaning, and to get the most out of your effort you are going to start by finding your largest files and deciding if you need to keep them around. But how do you find your largest files?
Solution
Use the -size predicate in the find command to select files above, below, or exactly a certain size. For example:
find . -size +3000k -print
Discussion
Like the numeric argument to -mtime
, the -size
predicate’s numeric argument can be
preceded by a minus sign, plus sign, or no sign at all to indicate less
than, greater than, or exactly equal to the numeric argument. So we’ve
indicated, in our example, that we’re looking for files that are greater
than the size indicated.
The size indicated includes a unit of k
for kilobytes. If you use c
for the unit, that means just bytes (or characters). If you use b, or don’t put any
unit, that indicates a size in blocks. (The block is a 512-byte block, historically a common unit in Unix
systems.) So we’re looking for files that are greater than 3 MB in
size.
See Also
man find
man du
Get bash Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.