5 ms·
Interesting is also find. It took me some time to accept that the directory must come first. E.g. find /path/to/dir -type f works, while find -type f /p
by protomikron 4y ago
Interesting is also find. It took me some time to accept that the directory must come first.
E.g.
find /path/to/dir -type f
works, while
find -type f /path/to/dir
does not.
- tomxor 4y agoYup, always seems to take a bit more conscious effort to remember that detail for find.
- mort96 4y agoProbably helps to think of find as its own weird pipeline rather than a command with options. The first element of the pipeline is the directory(/directories), then `-type f` filters out all the non-files, then `-name '*.txt'` filters out everything which doesn't end in ".txt", etc. That also helps to remember why `-maxdepth` has to be right after the directory; it affects which files even become part of the pipeline, it doesn't make sense as a pipeline element. The clearest proof that it's a pipeline is probably how it interacts with `-exec`: `find . -type d -exec echo {} \;` will print only directories, while `find . -exec echo {} \; -type d` will print both files and directories. Regardless though, I sure wish they would let you specify the directories at the end.
- yourad_io 4y agoVery insightful, I never realized this. Thank you
- chubot 4y agoI wrote a post about how to understand find syntax: find and test: How To Read And Write Them https://www.oilshell.org/blog/2021/04/find-test.html https://www.oilshell.org/blog/2021/04/find-test.html tl;dr The args AFTER the root dir args form a boolean expression language -- I call it the "I'm too lazy to write a lexer" pattern find /tmp -type -f -a -name 'foo*' test is the same way, e.g. test -f /tmp -a -f /bin
- michaelcampbell 4y agofind /tmp -type f -a -name 'foo*' # no "-" for the -type this is bitten me more often than I'd care to admit.
- chubot 4y agoOops, good point! Gah I honestly wonder where this wonky syntax came from ... i.e. was it a Bell Labs thing or later
- mmphosis 4y agoI just installed tesseract-ocr and it has a similar convention: tesseract imagename outputbase [options...] [configfile...]