Nicolas
Nicolas

Reputation: 137

Delete files except those whose name matches a string

I'm trying to delete all files (include subdir) in a directory but only files which not match specific file name: "equipe" "match" "express"

I'm trying to do it with this command

find . -type f '!' -exec grep -q "equipe" {} \; -exec echo rm {} \;
  1. That doesn't work. It echos files with "equipe" inside
  2. How can I do it with multiple strings? ("equipe" "match" "express")

Upvotes: 1

Views: 561

Answers (1)

anubhava
anubhava

Reputation: 785068

You may use this find:

find . -type f -not \( -name '*equipe*' -o -name '*match*' -o -name '*express*' \) -delete

Upvotes: 4

Related Questions