How to find and remove files in Linux/Unix

To remove multiple files such as *.tmp with one command find, use

find . -name "*.tmp"-exec rm -rf {} ;

OR

find . -type f -name "*.tmp" -exec rm -f {} ;

The only difference between above two syntax is that first command can remove irectories as well where second command only removes files.

More find and remove command

(a) Find all files having .tmp (*.tmp) extension in current directory and remove them:
$ find . -type f -name "*.tmp" -exec rm -f {} ;

(b) Find all target directories and remove them:
# find / -type d -name target -exec rm -f {} ;

(c) Find all *.tmp files in current directory and removes them with confirmation from user:
$ find . -type f -name "*.tmp" -exec rm -i {} ;

(Visited 2 times, 1 visits today)