Search code examples
unix

How to write a unix command or script to remove files of the same type in all sub-folders under current directory?


Is there a way to remove all temp files and executables under one folder AND its sub-folders?

All that I can think of is:

$rm -rf *.~

but this removes only temp files under current directory, it DOES NOT remove any other temp files under SUB-folders at all, also, it doesn't remove any executables.

I know there are similar questions which get very well answered, like this one: find specific file type from folder and its sub folder but that is a java code, I only need a unix command or a short script to do this.

Any help please? Thanks a lot!


Solution

  • Perl from command line; should delete if file ends with ~ or it is executable,

    perl -MFile::Find -e 'find(sub{ unlink if -f and (/~\z/ or (stat)[2] & 0111) }, ".")'