Applications can create a lot of temporary files sometimes, and these files aren’t always cleaned up automatically.
An example of this is when you run Python applications. Particularly if you’re a Python developer, your source code directories stack up with a .pyc version of each file, which is the cached compiled copy of the script.
To clean up (especially if you’re going to do a source commit or an upload somewhere to extend that example) files of a certain file extension, you can use this command line snippet:
$ find . -name "*.ext" -exec rm '{}' ';'
Obviously, replace *.ext with the pattern that you want to delete.
I shouldn’t need to say this, but use this with caution. Make sure you’re not accidentally going to delete something useful that matches the pattern you enter, and always keep backups yada yada. Tread carefully when batch deleting.


Linuxy wrote:
Why not simply use:
$ find . -name “*.ext” -delete
# Posted on 19-Jun-08 at 5:40 pm
Binny V A wrote:
I use this method all the time to delete .svn folders. I use the command…
find . -name .svn -exec rm -rf {} \;
The -delete option will not work in this case.
# Posted on 19-Jun-08 at 6:15 pm
Pantelis wrote:
I have another favorite
$ rm -rf `find . -name “smth”`
# Posted on 20-Jun-08 at 7:54 am
Carlos wrote:
$ find . -name “*.ext” | xargs rm
# Posted on 20-Jun-08 at 8:39 am
jono wrote:
why not
$ rm -R /dir *.ext
??
# Posted on 20-Jun-08 at 10:21 am
Carlos wrote:
rm can fail if the number of files is large.
# Posted on 20-Jun-08 at 3:44 pm
libkarl2 wrote:
for large file lists, try..
$ find /dir -name ‘*.ext’ -print | xargs -r rm
that way, you aren’t exec(3)ing rm for every file..
# Posted on 20-Jun-08 at 5:25 pm
Matt wrote:
Thank you so much! That was just what I was looking for. I should really learn how to use the find command…
# Posted on 21-Jun-08 at 5:27 am
Quick Command Line Tip - Recursively Delete Files of a Certain Type : HowtoMatrix wrote:
[...] Applications can create a lot of temporary files sometimes, and these files aren’t always cleaned up automatically. An example of this is when you run Python applications. Particularly if you’re a Python developer, your source code directories stack up with a .pyc version of each file, which is the cached compiled copy of the script. Read more at FOSSwire [...]
# Posted on 22-Jun-08 at 11:36 am