LPIC-1 Exam 101, Part 1 of 2, version 5.0 101-500 Question # 45 Topic 5 Discussion
101-500 Exam Topic 5 Question 45 Discussion:
Question #: 45
Topic #: 5
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 find command is used to search for files and directories that match certain criteria. The option -maxdepth can be used to restrict the command to searching down a particular number of subdirectories. The argument to -maxdepth is a positive integer that specifies the maximum depth of the directory tree to be searched. For example, -maxdepth 0 means only the current directory, -maxdepth 1 means the current directory and its direct subdirectories, and so on1. The option -maxdepth should be placed before any other expressions, as it affects the behavior of the whole command2. For example, to find all the files with the extension .txt in the current directory and its direct subdirectories, the command would be:
find . -maxdepth 1 -type f -name “*.txt”
The other options are not correct because:
A. -dirmax is not a valid find option.
C. -maxlevels is not a valid find option.
D. -depth is a valid find option, but it does not restrict the command to searching down a particular number of subdirectories. It only changes the order of the search, so that the files and directoriesare processed in depth-first order, meaning that the contents of a directory are processed before the directory itself1. References:
find(1) — Linux manual page
How to use find command to search for multiple extensions - Unix & Linux Stack Exchange
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit