GNU Find Flashcards: Expressions, Output & Pruning
Predict GNU find output, repair expression grouping and missing prints, and distinguish filtering from directory pruning with 40 short tree-based exercises.
เกี่ยวกับชุดการ์ดนี้
Practice GNU find expressions with 40 short, original exercises. Read a complete directory tree and command, predict the printed set, explain a missing result or an unexpected directory, or make a restricted repair. The examples separate expression truth, output actions, and directory descent. All fixtures use regular files and directories; output order is irrelevant.
The cards practice tree + command → output or branch explanation, faulty expression + stated goal → one constrained repair, and two commands with equal output → the difference in visited descendants. They move from name/path matching, shell quoting and implicit AND into precedence, grouping, negation and short-circuit printing, then pruning and mixed diagnosis. Closely related variants are separated by at least three other cards. Arbitrary output → command reversal and exhaustive equivalent rewrites are excluded because they do not give a single useful answer.
Scope: -name, -path, -type f/d, implicit/explicit AND, OR, negation, grouping, explicit/default -print, -prune, and one -depth caution showing why children-before-directory traversal defeats pruning. It is not a complete find course. Time, size and permission filters, depth-limit calculations, deletion, command execution, filename transport, symlinks, filesystem races and BSD/macOS portability are outside this deck.
The original trees, questions, answers and order were created with AI assistance. All 40 original fixtures and seven comparison or repair commands were checked with GNU findutils 4.10.0, both directly and through /bin/sh; visited-entry instrumentation checked traversal claims. Behavior facts were checked against the GNU find manual page and the manual included in the GNU findutils 4.10.0 release source. No manual prose, source code, competitor cards or third-party illustrations were copied. The cover is an original AI-generated illustration. CC0 1.0 applies to the original deck text, organization, metadata and cover to the extent applicable rights exist; factual behavior is not owned, and GNU documentation and source retain their own licenses.
An independent, unofficial learning resource with no affiliation with or endorsement by GNU or the Free Software Foundation.
การ์ดในชุดการ์ดนี้
การ์ด 1
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
atlas/ atlas/draft/ atlas/draft/seed.txt atlas/seed.txtfind atlas -name 'draft/seed.txt'Which paths print?
คำตอบ
None.
-nametests the final name component, so a pattern containing/cannot match these names.การ์ด 2
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
bay/ bay/card.md/ bay/card.md/inner bay/page.md bay/readme.txtfind bay -type f -name '*.md'Which paths print?
คำตอบ
bay/page.md. Adjacent tests mean AND: the entry must be a regular file and have a name ending in.md.การ์ด 3
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
cedar/ cedar/one.log cedar/two.log cedar/raw/ cedar/raw/three.logfind cedar -name '*.log'Why keep the quotes around the pattern?
คำตอบ
They pass the literal pattern
*.logto find instead of letting the shell expand it. All three.logfiles print, includingcedar/raw/three.log.การ์ด 4
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
dune/ dune/keep.txt dune/skip.txt dune/skip.txt.box/find dune -type f ! -name 'skip.txt'Which paths print?
คำตอบ
dune/keep.txt.!negates the following name test; the regular-file guard still applies.การ์ด 5
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
ember/ ember/first.c ember/second.h ember/cache.h/ ember/cache.h/chunkfind ember -type f -name '*.c' -o -name '*.h'Which paths print?
คำตอบ
ember/first.c,ember/second.h, and directoryember/cache.h. AND binds more tightly than OR, so the.hbranch has no regular-file guard.การ์ด 6
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
fern/ fern/.note.md fern/plain.md fern/deep/ fern/deep/.other.mdfind fern -name '*.md'Which paths print?
คำตอบ
All three
.mdfiles. GNU find's-namepattern can match a leading dot; the shell receives the quoted pattern unchanged.การ์ด 7
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
grove/ grove/pkg/ grove/pkg/part.txt grove/part.txtfind ./grove -path './grove/pkg/part.txt'Which paths print?
คำตอบ
./grove/pkg/part.txt.-pathmatches the encountered path, including the starting point's./prefix.การ์ด 8
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
harbor/ harbor/red.txt harbor/blue.txt harbor/green.txtfind harbor \( -name 'red.txt' -o -name 'blue.txt' \)Why are the parentheses escaped?
คำตอบ
So the shell passes
(and)as arguments to find for grouping. The printed set isharbor/red.txtandharbor/blue.txt.การ์ด 9
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
iris/ iris/a.csv iris/b.tsv iris/c.txtfind iris -name '*.csv' -o -name '*.tsv' -printWhich paths print?
คำตอบ
iris/b.tsvonly. A true.csvbranch short-circuits OR before-print; the explicit action also disables default printing for the command.การ์ด 10
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
juniper/ juniper/a.dat juniper/b.txt juniper/folder.dat/find juniper -type f -a -name '*.dat' -printIf only -a is removed, does the printed set change?
คำตอบ
No. Both forms print only
juniper/a.dat; an omitted operator between primaries means AND.การ์ด 11
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
kestrel/ kestrel/a.py kestrel/b.pyi kestrel/stub.pyi/find kestrel -type f -name '*.py' -o -name '*.pyi'Add only grouping parentheses so both name alternatives require a regular file. Give the repaired command.
คำตอบ
find kestrel -type f \( -name '*.py' -o -name '*.pyi' \)This prints
kestrel/a.pyandkestrel/b.pyi. The type guard now applies to the whole name choice.การ์ด 12
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
lagoon/ lagoon/start.txt lagoon/end.txt lagoon/other.txtfind lagoon -name 'start.txt' -print -o -name 'end.txt'Does lagoon/end.txt print?
คำตอบ
No. The second branch is true for it, but that branch has no print action. An explicit
-printanywhere in the expression disables default printing for the whole command.การ์ด 13
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
maple/ maple/red.txt maple/blue.txt maple/gray.txtfind maple -type f ! \( -name 'red.txt' -o -name 'blue.txt' \)Which paths print?
คำตอบ
maple/gray.txt. Negating the grouped OR excludes both named files.การ์ด 14
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
nectar/ nectar/a.json nectar/b.yaml nectar/c.inifind nectar -name '*.json' -o -name '*.yaml' -printAdd only parentheses so either filename branch reaches the final print. Give the repaired command.
คำตอบ
find nectar \( -name '*.json' -o -name '*.yaml' \) -printBoth
nectar/a.jsonandnectar/b.yamlprint; the action is now after the grouped choice.การ์ด 15
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
opal/ opal/release notes.txt opal/release.txt opal/notes.txtfind opal -type f -name 'release notes.txt' -printWhich paths print?
คำตอบ
opal/release notes.txt. The quotes make the space-bearing pattern one shell argument; the space is part of the filename.การ์ด 16
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
pine/ pine/real.txtfind pine -name 'absent.txt' -printWith readable entries and no I/O errors, what are the output and exit status?
คำตอบ
No paths; exit status 0. A false selection expression is not a process error.
การ์ด 17
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
quartz/ quartz/hot.txt quartz/cold.txt quartz/mild.txtfind quartz -type f \( ! -name 'hot.txt' -o ! -name 'cold.txt' \)Which paths print?
คำตอบ
All three regular files. Every name differs from at least one of the two distinct names; OR of these negatives excludes neither.
การ์ด 18
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
reed/ reed/pass.txt reed/fail.binfind reed -print -name '*.txt'Which paths print?
คำตอบ
reed,reed/pass.txt, andreed/fail.bin.-printruns before the name test; a later false result cannot undo output.การ์ด 19
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
sable/ sable/r.c sable/s.h sable/box.h/find sable \( -name '*.c' -o -name '*.h' \) -type f -printWhich paths print, and does putting the type test after the group break the guard?
คำตอบ
sable/r.candsable/s.h. It still works: the grouped name choice and the type test are joined by AND before printing.การ์ด 20
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
tamarind/ tamarind/cache/ tamarind/cache/old.txt tamarind/fresh.txtfind tamarind -type d -name 'cache' -prune -o -type f -printWhich paths print, and is cache/old.txt visited?
คำตอบ
Only
tamarind/fresh.txtprints. The cache directory is encountered and pruned; its child is not visited. The true pruning branch skips the right side of OR.การ์ด 21
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
umber/ umber/yes.txt umber/no.txtfind umber -name 'yes.txt' -o -name 'no.txt' -printFor umber/yes.txt, is the full expression true, and does it print?
คำตอบ
The expression is true, but it does not print. The left branch succeeds and OR skips the branch containing the only output action.
การ์ด 22
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
violet/ violet/cache/ violet/cache/hidden.txt violet/live.txtfind violet -name 'cache' -prune -o -type fWhich paths print?
คำตอบ
violet/cacheandviolet/live.txt.-prunealone does not disable default printing, and the full expression is true for the pruned directory. Its child is not visited.การ์ด 23
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
willow/ willow/build/ willow/build/a.txt willow/vendor/ willow/vendor/b.txt willow/src/ willow/src/c.txtfind willow -type d \( -name 'build' -o -name 'vendor' \) -prune -o -type f -printWhich paths print?
คำตอบ
willow/src/c.txtonly. Both directory names are inside the pruning branch, so neither excluded directory's descendants are visited.การ์ด 24
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
xenia/ xenia/cache/ xenia/cache/a.txt xenia/b.txtfind xenia -type f ! -path 'xenia/cache/*' -printDoes this prevent traversal into xenia/cache?
คำตอบ
No. It prints only
xenia/b.txt, but still visitsxenia/cache/a.txt. A path test filters output; it does not stop directory descent.การ์ด 25
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
yarrow/ yarrow/cache/ yarrow/cache/a.txt yarrow/src/ yarrow/src/cache/ yarrow/src/cache/b.txt yarrow/c.txtfind yarrow -path 'yarrow/cache' -prune -o -type f -printWhich regular files print?
คำตอบ
yarrow/src/cache/b.txtandyarrow/c.txt. Only the exact encountered pathyarrow/cacheis pruned; the nested cache is a different path.การ์ด 26
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
zinnia/ zinnia/cache/ zinnia/cache/a zinnia/bfind zinnia -type d -name 'cache' -prune -printDoes the pruned directory print, and are its children visited?
คำตอบ
zinnia/cacheprints; its child is not visited.-prunereturns true, so AND continues to the explicit-printfor that directory.การ์ด 27
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
acorn/ acorn/cache acorn/src/ acorn/src/cache/ acorn/src/cache/a acorn/src/livefind acorn -type d -name 'cache' -prune -o -type f -printWhich paths print?
คำตอบ
acorn/cacheandacorn/src/live. The type guard keeps the regular file named cache out of the pruning branch; the nested cache directory is pruned.การ์ด 28
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
birch/ birch/build/ birch/build/a.txt birch/vendor/ birch/vendor/b.txt birch/c.txtfind birch -name 'build' -o -name 'vendor' -prune -o -type f -printWhich excluded directory still has its child visited and printed?
คำตอบ
birch/build: itsa.txtchild prints, along withbirch/c.txt. Matching the first OR branch skips-prune; only the vendor branch reaches it.การ์ด 29
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
cobalt/ cobalt/cache/ cobalt/cache/a.txt cobalt/b.txtfind cobalt -depth -name 'cache' -prune -o -type f -printDoes pruning prevent the cache child's visit or output?
คำตอบ
No. Both
cobalt/cache/a.txtandcobalt/b.txtprint.-depthprocesses children before their directory, so pruning that directory comes too late.การ์ด 30
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
drift/ drift/cache/ drift/cache/a.txt drift/lib/ drift/lib/cache/ drift/lib/cache/b.txt drift/c.txtfind drift -type d -name 'cache' -prune -o -type f -printWhich regular files print?
คำตอบ
drift/c.txtonly. A directory-name test catches both the top-level cache and the nested one.การ์ด 31
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
easel/ easel/a.txt easel/sub/ easel/sub/b.txtfind easel -name 'easel' -prune -o -type f -printWhich paths print?
คำตอบ
None. The starting directory itself matches and is pruned, so none of its descendants are visited.
การ์ด 32
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
flint/ flint/cache/ flint/cache/a.txt flint/b.txtfind flint -type d -name 'cache' -prune -type f -printWhy does even flint/b.txt fail to print?
คำตอบ
Every primary is joined by AND. Regular files fail
-type d; the pruned cache directory fails-type f. No entry reaches-print.การ์ด 33
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
garnet/ garnet/cache/ garnet/cache/a garnet/bfind garnet \( -name 'cache' -prune -o -type f \) -printWhich paths print?
คำตอบ
garnet/cacheandgarnet/b. The final print applies to either successful branch, including the true pruning branch.การ์ด 34
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
heath/ heath/cache/ heath/cache/a heath/lib/ heath/lib/cache/ heath/lib/cache/b heath/cfind heath -path 'heath/cache' -prune -o -type f -printReplace only -path 'heath/cache' so every directory named cache is pruned, wherever nested. Give the replacement.
คำตอบ
-type d -name 'cache'. The repaired command prints onlyheath/c; it prunes both cache directories.การ์ด 35
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
indigo/ indigo/.stash/ indigo/.stash/a.txt indigo/.memo.txt indigo/b.txtfind indigo -type d -name '.stash' -prune -o -type f -name '*.txt' -printWhich paths print?
คำตอบ
indigo/.memo.txtandindigo/b.txt. The hidden directory is pruned, while the quoted name pattern still matches the hidden regular file.การ์ด 36
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
jasper/ jasper/build/ jasper/build/a jasper/vendor/ jasper/vendor/b jasper/cfind jasper -name 'build' -o -name 'vendor' -prune -o -type f -printAdd only parentheses so both named directories reach -prune. Give the repaired command.
คำตอบ
find jasper \( -name 'build' -o -name 'vendor' \) -prune -o -type f -printOnly
jasper/cprints. Grouping makes either name lead to the pruning action.การ์ด 37
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
kelp/ kelp/cache/ kelp/cache/a.txt kelp/b.txtfind kelp -type f ! -path 'kelp/cache/*' -printCompare with:
find kelp -path 'kelp/cache' -prune -o -type f -printBoth commands print kelp/b.txt. Which command still visits kelp/cache/a.txt?
คำตอบ
The first command. Its negated path test hides the descendant from output but does not prevent visiting it; the second command prunes the directory.
การ์ด 38
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
linen/ linen/cache/ linen/cache/a.md linen/report.md/ linen/report.md/note.txt linen/b.mdfind linen -type d -name 'cache' -prune -o -type f -name '*.md' -printDoes directory linen/report.md or its child print?
คำตอบ
Neither. The directory fails the regular-file guard, and its child fails the
.mdname test. Onlylinen/b.mdprints; report.md is still traversed.การ์ด 39
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
moss/ moss/cache/ moss/cache/a moss/bfind ./moss -path 'moss/cache' -prune -o -type f -printReplace only the path pattern so the cache directory is actually pruned. Give the replacement.
คำตอบ
'./moss/cache'. Encountered paths retain the starting point's./; the repaired command prints only./moss/b.การ์ด 40
คำถาม
GNU find; run from this complete tree's parent. Trailing / marks directories; other entries are regular files. Ignore output order.
north/ north/cache/ north/cache/a.c north/src/ north/src/b.c north/src/c.h north/src/folder.h/ north/src/folder.h/d.txt north/release notes.hfind north -type d -name 'cache' -prune -o -type f \( -name '*.c' -o -name '*.h' \) -printWhich paths print?
คำตอบ
north/src/b.c,north/src/c.h, andnorth/release notes.h. Pruning excludes the cache subtree; grouping shares the regular-file guard across both suffixes, so folder.h does not print.
40 การ์ด
GNU Find Flashcards: Expressions, Output & Pruning
Nibomo จะเปิดขึ้นเพื่อให้คุณเริ่มเรียนได้ทันที