Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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



> Second does what I expect

Both do what you expect once you understand `-name` and `-delete` are predicates (not switches) and find short-cuts.


The 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.


Yes, well I know that now that I lost the contents of a project directory. Live and learn.


I'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...




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: