bash - Please explain the implied -print action in the find command -
i fell trap of believing if find in bash prunes files , finds remaining files (not directories), output remaining files.
it didn't work expected.
here's simplified example. i've directory structure follows:
a ├── 1.log ├── 1.tgz ├── 1.txt ├── b │ ├── 2.log │ ├── 2.tgz │ └── 2.txt ├── c │ ├── 3.log │ ├── 3.tgz │ └── 3.txt └── d └── e ├── 4.log ├── 4.tgz └── 4.txt let's want find files aren't *.log or *.tgz. (i realise that's left *.txt files there's obvious way find those, that's not going case, please indulge me.)
my original command was:
find \( -name '*.log' -o -name '*.tgz' \) -prune -o -type f i expected work, listed files:
a/1.log a/b/2.tgz a/b/2.txt a/b/2.log a/d/e/4.log a/d/e/4.txt a/d/e/4.tgz a/1.txt a/1.tgz a/c/3.tgz a/c/3.txt a/c/3.log according the man page find:
if whole expression contains no actions other -prune or -print, -print performed on files whole expression true.
to mind, whole expression true *.txt files. if simple like:
find -type f the -print implied according above, , files listed.
the thing confused me if add -print end of original command, works expect:
a/b/2.txt a/d/e/4.txt a/1.txt a/c/3.txt since kind of expected -print implied anyway, wouldn't expect have effect does.
could please explain how should mentally parse such find commands don't fall traps again?
wiki
Comments
Post a Comment