Mac -- remove all files with a certain extension from a directory tree [duplicate]
Solution 1:
Use the find
tool:
find /path -name '*.orig' -delete
Note that the wildcard must be quoted (either as "*.orig"
or '*.orig'
or \*.orig
), as you want it to be only handled by 'find' but not by the shell.
Some operating systems might not have the -delete
option, in which case make it invoke rm
:
find /path -name "*.orig" -exec rm -i {} \;
Solution 2:
I prefer this method (very similar to @grawity) but with the type of file
included:
find /path . -name '*.orig' -type f -delete
Solution 3:
Can you execute shell commands in bash? This would do the trick:
find /path/to/your/tree | egrep .orig$ | xargs rm