So the following behaviour of unix find just cost me dearly:
> touch foo
> touch bar
> ls
bar foo
> find . -name '*oo' -delete
> ls
bar
> touch baz
> ls
bar baz
> find . -delete -name '*ar'
> ls
> #WHAAAT?
How does this make sense?
filesfind
So the following behaviour of unix find just cost me dearly:
> touch foo
> touch bar
> ls
bar foo
> find . -name '*oo' -delete
> ls
bar
> touch baz
> ls
bar baz
> find . -delete -name '*ar'
> ls
> #WHAAAT?
How does this make sense?
Best Answer
The command line of find is made from different kinds of options, that are combined to form expressions.
The
find
option-delete
is an action.That means it is executed for each file matched so far.
As first option after the paths, all files are matched... oops!
It is dangerous - but the man page at least has a big warning:
From
man find
:From further up in
man find
:On trying out what a
find
command will do:To see what a command like
will delete, you can first replace the action
-delete
by a more harmless action - like-fls
or-print
:This will print which files are affected by the action.
In this example, the -print can be left out. In this case, there is not action at all, so the most obvious is added implicitly:
-print
. (See the second paragraph of the section "EXPRESSIONS" cited above)