Search code examples
linuxubuntufindexecrm

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.


Solution

  • 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.