3 ms·
find -delete -name ".pyc" is not the same as find -name ".pyc" -delete First one nukes everything including the git repo Second does what I expect
by parfe 15y ago
find -delete -name ".pyc"
is not the same as
find -name ".pyc" -delete
First one nukes everything including the git repo
Second does what I expect
- masklinn 15y ago> Second does what I expect Both do what you expect once you understand `-name` and `-delete` are predicates (not switches) and find short-cuts.
- parfe 15y agoYes, well I know that now that I lost the contents of a project directory. Live and learn.
- shabble 15y agoI'm suitably conditioned at this point to always give it a trial run with -print before using -delete, and -exec echo '{}' \; before any potentially dangerous commands. Once bitten, etc...
- shabble 15y agoThe other big gotcha that took a while to sink in was find -name "foo*" -or -name "*bar" -print which should actually be find \( -name "foo*" -or -name "*bar" \) -print to do what you might expect (print things matching beginning with foo or ending with bar) Without the parens, it gets interpreted as -name "foo*" -or ( -name "*bar" -and -print ), and hence only prints things that match the latter predicate.