nerdexam
CompTIA

LX0-103 · Question #17

In a nested directory structure, which find command line option would be used to restrict the command to searching down a particular number of subdirectories?

The correct answer is B. -maxdepth. The find command uses -maxdepth to limit how many directory levels deep the search will descend from the starting point.

GNU and Unix Commands

Question

In a nested directory structure, which find command line option would be used to restrict the command to searching down a particular number of subdirectories?

Options

  • A-dirmax
  • B-maxdepth
  • C-maxlevels
  • D-n
  • E-s

How the community answered

(18 responses)
  • B
    94% (17)
  • D
    6% (1)

Why each option

The find command uses -maxdepth to limit how many directory levels deep the search will descend from the starting point.

A-dirmax

-dirmax is not a valid find option and will cause find to report an unknown predicate error.

B-maxdepthCorrect

The -maxdepth option is the valid find predicate that restricts directory traversal to the specified number of levels. For example, -maxdepth 1 searches only the starting directory, and -maxdepth 2 includes one level of subdirectories. It is a standard GNU find option documented in the find man page.

C-maxlevels

-maxlevels is not a valid find option - the correct option name is -maxdepth.

D-n

-n is not a depth-limiting option for find; it has no defined meaning in this context.

E-s

-s is not a depth-limiting option for find and does not restrict directory traversal.

Concept tested: find command depth restriction with -maxdepth

Source: https://man7.org/linux/man-pages/man1/find.1.html

Topics

#find#maxdepth#directory traversal#file search

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice