010-100 · Question #54
Which of the following commands will output a list of all of the file names, under your home directory and all subdirectories, which have file names ending with .pdf?
The correct answer is D. find ~ -name '*.pdf'. The find command searches a directory tree for files matching specified criteria. Using the -name option with a wildcard pattern and specifying ~ as the start path covers the home directory and all subdirectories.
Question
Which of the following commands will output a list of all of the file names, under your home directory and all subdirectories, which have file names ending with .pdf?
Options
- Asearch .pdf
- Bls -name -R '*.pdf'
- Cfind /home/*.pdf
- Dfind ~ -name '*.pdf'
How the community answered
(59 responses)- A10% (6)
- B2% (1)
- C5% (3)
- D83% (49)
Why each option
The find command searches a directory tree for files matching specified criteria. Using the -name option with a wildcard pattern and specifying ~ as the start path covers the home directory and all subdirectories.
search is not a standard Linux command for finding files by name in a directory tree.
ls does not have a -name option; -R lists recursively but ls cannot filter by filename pattern the way find does.
find /home/*.pdf incorrectly uses shell glob expansion in the path argument instead of the -name predicate, and would not recursively search subdirectories under the home directory.
find ~ -name '*.pdf' starts the search at the user's home directory (~), recursively traverses all subdirectories by default, and uses -name '*.pdf' to match only files whose names end with .pdf, producing the desired output.
Concept tested: Using find command with -name for recursive file search
Source: https://man7.org/linux/man-pages/man1/find.1.html
Topics
Community Discussion
No community discussion yet for this question.