Delete files recursively with a specific extension
Sep 10th, 2008 by paolo
If you want to delete, for example, only .bak files throughout a directory tree you can try with the following command:
$ find . -name *.bak -exec rm {} \;
Using the same approach you can solve more complex problems. For example you can delete recursively all directories older than one week:
$ find . -mtime +7 -type d -exec rm -rf {} \;
Another example, for subversion users, could be the way to clean up a check-out directory:
$ find . -name lock -exec rm {} \;
Or a way to drop all .svn metadata directories:
$ find . -name .svn -exec -type d rm -rf {} \;
Now it’s up to you to find other examples…


Ma che fico!!!! E molto utile.