Traverse /var/log directly on the current filesystem.
Print only regular files whose names end in .log.
Which command is appropriate?
find START -type f -name PATTERN traverses the hierarchy and applies the file-type and basename pattern conditions together.
Detailed explanation
locate /var/log '*.log'Incorrect. locate searches a database and does not take find's start-path and type predicates in this form.
Incorrect. locate searches a database and does not take find's start-path and type predicates in this form.
find /var/log -type d -name '*.log'Incorrect. -type d selects directories, not regular files.
Incorrect. -type d selects directories, not regular files.
find /var/log -type f -name '*.log'Correct. find /var/log -type f -name '*.log' selects matching regular files.
Correct. find /var/log -type f -name '*.log' selects matching regular files.
whereis /var/log '*.log'Incorrect. whereis locates command files and manuals, not arbitrary file trees.
Incorrect. whereis locates command files and manuals, not arbitrary file trees.
Try it yourself
An example you can run in a temporary verification environment.
find /var/log -maxdepth 1 -type f -name '*.log' -printExpected result
/var/log直下に該当ファイルがあれば表示するKey points
- Starting point
- -type f
- Quote the pattern
Notes
- Environment: GNU findutils 4.9以降
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.