Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The find Command with -exec Does Not Run the -exec Command

I want to write a simple command to cleanup my project files, so I used:

find . -type f -name "*.o" -o -name "*.a" -o -name "*.ko" -exec rm '{}' +

Oddly it didn't work. And when I removed " -exec rm '{}' +" I could see that it dumped the files out the terminal, so it looks like my expression is correct. I even tried changing "'{}' +" to "'{}' \;", but this also didn't work. I also tried replacing rm with echo but nothing was displayed in the terminal. Am I doing something wrong?

Using Ubuntu 12.04.

like image 893
John Avatar asked Jul 11 '26 10:07

John


1 Answers

Try using it like this:

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

When using multiple files with find combined with exec it often only acts on the last filename.

like image 198
l'L'l Avatar answered Jul 13 '26 23:07

l'L'l