bob
bob

Reputation: 27

Using find to delete some files

I'm trying to delete some files using find like the line below.

find / -name "file1" -o -name "file2" -delete

My problem is that this line returns true if it finds "file1" but do not delete it, just "file2".

I've tried to use parentheses, but it's not working too.

Upvotes: 1

Views: 49

Answers (1)

larsks
larsks

Reputation: 312520

You didn't show what your command line looked like when you "tried to use parentheses". When you write:

find / -name "file1" -o -name "file2" -delete

The order-of-operations means that the expression becomes, effectively:

( -name "file1" ) -o ( -name "file2" -delete )

So of course it only deletes file2. If you change your parentheses it should work just fine:

find / \( -name "file1" -o -name "file2" \) -delete

Upvotes: 2

Related Questions