nerdexam
LPI

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.

The Power of the Command Line

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)
  • A
    10% (6)
  • B
    2% (1)
  • C
    5% (3)
  • D
    83% (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.

Asearch .pdf

search is not a standard Linux command for finding files by name in a directory tree.

Bls -name -R '*.pdf'

ls does not have a -name option; -R lists recursively but ls cannot filter by filename pattern the way find does.

Cfind /home/*.pdf

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.

Dfind ~ -name '*.pdf'Correct

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

#find command#file search#wildcards

Community Discussion

No community discussion yet for this question.

Full 010-100 Practice