Find "*.c" and "Makefile" and then delete them with one line

find "*.c" and "Makefile" and then delete them with one line

find . \( -name "*.c" -o -name "Makefile" \) -type f -exec rm {} \;

Note : Please use with care and only when you are sure. I would suggest to first list the file with

find . \( -name "*.c" -o -name "Makefile" \) -type f
find . \( -name "*.c" -o -name "Makefile" \) -type f | xargs rm

This would be slightly quicker than running find with -exec switch because for each file the find command finds, the commands in exec would be executed; as against the xargs method where all the files are first found, and then the rm is applied over the entire list. For instance, if the find commands fetches 20 files, with the exec version, rm would be called 20 times. With the xargs version, it will be called only once. Of course, the difference may be very little.

You might find this thread interesting to read.

Make sure you don't delete anything that is critical to the Operating System either. You might not notice until the next boot.

Be careful. Read all the files you are planning to delete first. If you just want to scan once:-

find . \( -name "*.c" -o -name "Makefile" \) -type f -exec echo rm {} \; > /tmp/rm_cmds

After confirming (or even editing) the commands listed, just set as executable and run it:-

chmod 700 /tmp/rm_cmds
/tmp/rm_cmds

Remember you might only get one chance to avoid breaking it. How is your recovery plan?

Robin