On Thu, 19 Jan 2006, Mathias Homann wrote:
Am Donnerstag, 19. Januar 2006 20:10 schrieb Shaun Q:
Hi there guys!
Is there a way to only delete files in a directory over a certain size? I was hoping to find someway to do it with rm, but I haven't had much luck finding an option to do so yet.
find /path/to/directory -size +1k -exec rm {} \;
finds all files bigger than one kbyte in /path/to/directory and executes the command on them, which in the example is rm.
other size indicators: b is blocks of 512bytes, c is bytes (characters), w is words (two bytes).
Please let this be taken as constructive criticism.
Of the three solutions posted, this one is the safest.
One of the other two (Per Jesson's) did not handle situations in which
the name of the file contained spaces in its name. Instead of using:
find <dir> -size +1M | xargs rm
use:
find <dir> -size +1m -print0 | xargs -0 rm
And the other solution which used a script also doesn't properly deal
with spaces, and is far too long besides. ;-)
The only real difference between using -exec (my favored method) and
xargs is that with xargs you can have multiple files deleted per 'rm'
invocation - if you are deleting /lots/ of files this can be an issue.
find is almost unbelievably powerful and is unfortunately one of the
most underutilized commands around.
--
Carpe diem - Seize the day.
Carp in denim - There's a fish in my pants!
Jon Nelson