>_ IzzyLab

Hands-on task

This task is step 9 of the course “find and xargs: search and bulk operations”

find -maxdepth: no descending into subdirectories

easy~3 min

/root/etc has .conf files both at the top level and in the nested sub/ directory. Find .conf files only at the top level (without descending into subdirectories) and write their paths (/root/etc/…) to /root/top.txt.

What you'll practise:
  • find
  • -maxdepth
  • traversal depth
  • -name

Topic breakdown

find is recursive by default, but you can limit the traversal depth: -maxdepth N doesn't go deeper than N levels (0 — only the starting path, 1 — its direct contents), and -mindepth N skips the top levels. This speeds up the search and makes the selection more precise — for example, "configs only in /etc, but not in /etc/*/". -maxdepth is not a test but a global option: it applies to the whole traversal wherever it appears, but GNU find warns if it comes after tests — so it is written right after the starting directory. Limiting depth is especially useful on large trees, where a full recursive walk is expensive.

What's checked

  1. top-level files found
  2. extras excluded

What it looks like