lipo
lipo

Reputation: 237

Linux find and remove

Hello the below is not removing the files that are ending with char 'o' but I'm not sure why.

find . -name '.*o' -type f -ok rm '{}'

here is my current error

error

Thanks so much!!

Upvotes: 0

Views: 143

Answers (2)

Malik
Malik

Reputation: 904

While Jatinj Mehrotra is correct, there are still two things unmentioned:

  1. -exec and -ok are simmilar, but not the same. -exec will execute your command on every file find finds. -ok will actually ask you for every single file or directory, if you are ok with executing the command on it.
  2. Your actual problem is, that you are missing a \ befor your ;. In shell the semi-colon is a delimiter for a command. So command1; command2 will be interpreted as if you typed command1, then pressed enter, and then typed command2 and press enter. But in this case the semicolon is actually a parameter to find -exec. It tells find that you want that command executed on every single item individually. You can also use a +, which tells find to replace the {} with a space-seperated list of everything it finds.

Upvotes: 0

Jatin Mehrotra
Jatin Mehrotra

Reputation: 11513

This worked for me

find . -name '*o'  -type f -exec rm -f {} \;

Upvotes: 2

Related Questions