Deleting Files Recursively

I periodically convince myself that recursively deleting files of a certain type is something that the rm command can do. Let me save you some man page reading. It can't.

I found myself wanting to delete .LCK files (created by Dreamweaver's check in/out functionality) scattered all over the web directories on a Linux server. I found the find command offers an -exec switch which you can use to call rm to do the work.

find . -name "*.LCK" -exec rm {} \;

Being command-line lazy, I created a quick and dirty script and saved it in my personal bin directory.

# script to delete files recursively by file extension
if [ $1 ]
   find . -name "*.$1" -exec rm {} \;
   echo "usage: rmtree ";
   echo "example: rmtree LCK";

Posted on January 21, 2006 in linux . | 8 Trackbacks, 0 Comments


Post a comment

Remember Me?

(you may use HTML tags for style)