Linux and Command-Line Basics
Which of the following describes the files found when find /data -name "*.log" -mtime +7 -size +100M is run with GNU find?
- AFiles whose names end in .log, last modified 8 or more days ago, and larger than 100 MiB
- BFiles whose names end in .log, last modified within 7 days, and larger than 100 MiB
- CFiles whose names end in .log, created 8 or more days ago, and larger than 100 MiB
Show answer and explanation
Answer: A. Files whose names end in .log, last modified 8 or more days ago, and larger than 100 MiB
-name "*.log" selects names ending in .log, -mtime the time the contents were last modified, and -size +100M sizes larger than 100 MiB. -mtime compares the elapsed time counted in 24-hour units with the fraction discarded, so +7 means "more than 7", that is, 8 days (192 hours) or more; a file only 7 days and 23 hours old is not selected. Files modified within 7 days are selected with -mtime -7. *.log is quoted so that the shell does not expand it first into file names in the current directory.
- A. Correct. +7 means a day count, with the fraction discarded, greater than 7, that is, 8 or more days.
- B. Selecting files modified within 7 days is -mtime -7. + means "more than" and - means "less than".
- C. -mtime compares the time the contents were last modified, not the time the file was created.