Wednesday, November 21, 2007

Find and Delete Files

Need to find a pattern in a filename and delete all those files?

find . -name "ftp.log" -exec rm '{}' \;

You can replace "ftp.log" with "*.log" to get all files with the .log extension. The "." after find just means "search at the current directory".

I got this from this website: http://www.aota.net/forums/archive/index.php/t-20930.html

1 comment:

Ramon said...

if you want to remove folders and all its child add -fvr after rm:

find . -name "ftp.log" -exec rm -fvr '{}' \;