GNU find Depth Flashcards: -maxdepth and -mindepth

Practice GNU find depth limits with short command and output drills. Predict which paths print and choose -maxdepth and -mindepth for the levels you need.

ಈ ಡೆಕ್ ಬಗ್ಗೆ

Trace GNU find through small directory trees. Predict which paths print, write commands for a target depth or range, and fix off-by-one errors. Each answer gives the result and a short explanation.

Start at depth zero and with direct children. Then combine -mindepth and -maxdepth for exact levels and inclusive ranges. Later cards mix depth with file and directory tests, hidden entries, multiple starting points, and a case where a minimum depth blocks pruning.

The examples focus on listing paths. File changes, cross-platform syntax, and output order are outside the scope. These original exercises were drafted with AI assistance and checked against GNU Findutils.

ಈ ಡೆಕ್‌ನ ಕಾರ್ಡ್‌ಗಳು

  1. ಕಾರ್ಡ್ 1

    ಪ್ರಶ್ನೆ

    What depth does GNU find assign to a starting point?

    ಉತ್ತರ

    Depth 0. With find vault, vault itself is at depth 0.

  2. ಕಾರ್ಡ್ 2

    ಪ್ರಶ್ನೆ

    Which GNU find option limits how far it descends?

    ಉತ್ತರ

    -maxdepth N. GNU find can visit entries at depth N and stops descending there.

  3. ಕಾರ್ಡ್ 3

    ಪ್ರಶ್ನೆ

    Which GNU find option skips tests and actions on entries shallower than a given depth?

    ಉತ್ತರ

    -mindepth N. Tests and actions start at depth N. The minimum by itself still allows descent through shallower directories.

  4. ಕಾರ್ಡ್ 4

    ಪ್ರಶ್ನೆ

    kiosk is a directory. What does this GNU find command print?

    find kiosk -maxdepth 0 -type f -print
    

    ಉತ್ತರ

    No paths print. Only kiosk is eligible by depth, and -type f accepts regular files.

  5. ಕಾರ್ಡ್ 5

    ಪ್ರಶ್ನೆ

    When GNU find starts at board, what is the depth of its direct child board/pin?

    ಉತ್ತರ

    Depth 1. Moving from a directory to any of its children adds one level.

  6. ಕಾರ್ಡ್ 6

    ಪ್ರಶ್ನೆ

    Which paths does this GNU find command print, in any order?

    orchard/
    ├── basket/
    │   └── spare
    └── map
    
    find orchard -maxdepth 1 -print
    

    ಉತ್ತರ

    orchard
    orchard/basket
    orchard/map
    

    The starting directory is at depth 0. Its direct children are at depth 1.

  7. ಕಾರ್ಡ್ 7

    ಪ್ರಶ್ನೆ

    Which paths does GNU find print, in any order?

    lab/
    ├── meter
    └── bench/
        └── cable
    
    find lab -mindepth 1 -print
    

    ಉತ್ತರ

    lab/meter
    lab/bench
    lab/bench/cable
    

    The starting point is skipped. Its children and deeper descendants are eligible.

  8. ಕಾರ್ಡ್ 8

    ಪ್ರಶ್ನೆ

    Using GNU find, print the path ticket only if that starting point is a regular file.

    ಉತ್ತರ

    find ticket -maxdepth 0 -type f -print
    

    Depth 0 selects the named starting point. -type f checks whether it is a regular file.

  9. ಕಾರ್ಡ್ 9

    ಪ್ರಶ್ನೆ

    Which depth options make GNU find apply tests and actions at exactly depth N?

    ಉತ್ತರ

    -mindepth N -maxdepth N. Both bounds include N, so only that level is eligible.

  10. ಕಾರ್ಡ್ 10

    ಪ್ರಶ್ನೆ

    Which paths does GNU find print, in any order?

    studio/
    ├── .theme
    ├── sketch
    └── drafts/
        └── notes
    
    find studio -maxdepth 1 -type f -print
    

    ಉತ್ತರ

    studio/.theme
    studio/sketch
    

    A leading dot does not change depth or file type. drafts is a directory, and notes is too deep.

  11. ಕಾರ್ಡ್ 11

    ಪ್ರಶ್ನೆ

    Which paths does GNU find print, in any order?

    inbox/
    ├── notice.txt
    └── reports/
        └── weekly.txt
    
    find inbox -mindepth 2 -type f -print
    

    ಉತ್ತರ

    inbox/reports/weekly.txt
    

    GNU find passes through reports at depth 1 and tests its child at depth 2.

  12. ಕಾರ್ಡ್ 12

    ಪ್ರಶ್ನೆ

    Which paths does GNU find print, in any order?

    museum/
    ├── audio.mp3
    └── west/
        └── hall/
    
    find museum -maxdepth 1 -type d -print
    

    ಉತ್ತರ

    museum
    museum/west
    

    Both directories fall within depths 0 and 1. -type d selects directories.

  13. ಕಾರ್ಡ್ 13

    ಪ್ರಶ್ನೆ

    Which paths does GNU find print, in any order?

    camp/
    ├── water
    └── trail/
        ├── fork/
        │   └── marker
        └── sign
    
    find camp -mindepth 2 -maxdepth 2 -print
    

    ಉತ್ತರ

    camp/trail/fork
    camp/trail/sign
    

    Both entries are at depth 2. Directories and regular files can both print at that level.

  14. ಕಾರ್ಡ್ 14

    ಪ್ರಶ್ನೆ

    Which GNU find depth options select depths 2 through 4, including both ends?

    ಉತ್ತರ

    -mindepth 2 -maxdepth 4. The eligible depths are 2, 3 and 4.

  15. ಕಾರ್ಡ್ 15

    ಪ್ರಶ್ನೆ

    Which paths does GNU find print, in any order?

    desk/
    └── lamp
    rack/
    └── shelf/
        └── box
    
    find desk rack -mindepth 1 -maxdepth 1 -print
    

    ಉತ್ತರ

    desk/lamp
    rack/shelf
    

    GNU find counts depth separately from desk and from rack.

  16. ಕಾರ್ಡ್ 16

    ಪ್ರಶ್ನೆ

    archive is a directory. What does this GNU find command print?

    find archive -mindepth 3 -maxdepth 1 -print
    

    ಉತ್ತರ

    No paths print. No depth satisfies both bounds.

  17. ಕಾರ್ಡ್ 17

    ಪ್ರಶ್ನೆ

    Using GNU find, list the regular files directly inside server whose names end in .log.

    ಉತ್ತರ

    find server -maxdepth 1 -type f -name '*.log' -print
    

    The cap reaches direct children. -type f excludes the starting directory, and the quotes pass *.log to GNU find as a pattern.

  18. ಕಾರ್ಡ್ 18

    ಪ್ರಶ್ನೆ

    This GNU find command prints parts itself. Which option would you add to keep only its direct children?

    find parts -maxdepth 1 -print
    

    ಉತ್ತರ

    Add -mindepth 1. With -maxdepth 1, that leaves exactly depth 1.

  19. ಕಾರ್ಡ್ 19

    ಪ್ರಶ್ನೆ

    GNU find starts at both depot and depot/aisle. What is the depth of depot/aisle/bin in each search?

    ಉತ್ತರ

    Depth 2 from depot and depth 1 from depot/aisle. Each starting point has its own depth 0.

  20. ಕಾರ್ಡ್ 20

    ಪ್ರಶ್ನೆ

    printshop is a directory containing jobs. What does this GNU find command print?

    find printshop -maxdepth 0 -print
    

    ಉತ್ತರ

    printshop. The cap is 0, so GNU find evaluates only the starting point.

  21. ಕಾರ್ಡ್ 21

    ಪ್ರಶ್ನೆ

    Which paths does GNU find print, in any order?

    bakery/
    └── bin/
        └── tray/
            └── box/
                └── tag
    
    find bakery -mindepth 2 -maxdepth 3 -print
    

    ಉತ್ತರ

    bakery/bin/tray
    bakery/bin/tray/box
    

    The two bounds include depths 2 and 3.

  22. ಕಾರ್ಡ್ 22

    ಪ್ರಶ್ನೆ

    Using GNU find, list only the directories immediately inside music.

    ಉತ್ತರ

    find music -mindepth 1 -maxdepth 1 -type d -print
    

    Depth 1 selects direct children. -type d keeps directories among those children.

  23. ಕಾರ್ಡ್ 23

    ಪ್ರಶ್ನೆ

    Which paths does this GNU find command print, in any order?

    project/
    ├── cache/
    │   └── token
    └── src/
        └── index
    
    find project -path 'project/cache' -prune -o -print
    

    ಉತ್ತರ

    project
    project/src
    project/src/index
    

    At project/cache, -prune stops descent and the successful left side of -o skips -print.

  24. ಕಾರ್ಡ್ 24

    ಪ್ರಶ್ನೆ

    Which paths does GNU find print, in any order?

    shelf/
    ├── .spare/
    │   └── screw
    └── tin/
        └── washer
    
    find shelf -mindepth 2 -maxdepth 2 -type f -print
    

    ಉತ್ತರ

    shelf/.spare/screw
    shelf/tin/washer
    

    GNU find also descends through dot-prefixed directories. Both files are two levels from shelf.

  25. ಕಾರ್ಡ್ 25

    ಪ್ರಶ್ನೆ

    GNU find starts at market/stalls. Which depth options select just the direct children of that starting point?

    ಉತ್ತರ

    -mindepth 1 -maxdepth 1. The full starting path market/stalls is at depth 0.

  26. ಕಾರ್ಡ್ 26

    ಪ್ರಶ್ನೆ

    Using GNU find, list every entry at depth 3 or deeper with library as the starting point.

    ಉತ್ತರ

    find library -mindepth 3 -print
    

    Tests and actions start at depth 3. Omitting -maxdepth leaves deeper entries eligible.

  27. ಕಾರ್ಡ್ 27

    ಪ್ರಶ್ನೆ

    Does this GNU find command prune build/cache, a directory directly under build?

    find build -mindepth 2 -path 'build/cache' -prune -o -print
    

    ಉತ್ತರ

    No. build/cache is at depth 1, where -mindepth 2 skips the tests and actions. GNU find can descend into it.

  28. ಕಾರ್ಡ್ 28

    ಪ್ರಶ್ನೆ

    logs/ready/worker.log is a regular file, but this GNU find command misses it. What smallest change to the depth cap makes it eligible?

    find logs -maxdepth 1 -type f -name '*.log' -print
    

    ಉತ್ತರ

    Change -maxdepth 1 to -maxdepth 2. worker.log sits two levels below logs.

Three teal disks on separate steps of a small wooden staircase.

28 ಕಾರ್ಡ್‌ಗಳು

GNU find Depth Flashcards: -maxdepth and -mindepth

ಈ ಡೆಕ್ ಅನ್ನು ಉಚಿತವಾಗಿ ಅಧ್ಯಯನ ಮಾಡಿ

ಅಧ್ಯಯನ ಆರಂಭಿಸಲು Nibomo ತೆರೆಯುತ್ತದೆ.

ಹೋಲುವ ಡೆಕ್‌ಗಳು