How we will find more accurately all
.cpp files in the users home directory that were modified no more than 5 minutes ago?
find can select files on various time conditions:
find ~ -type f -name '*.cpp' -mmin -5 -ls
The command lists the files
- in the directory
~and it's subdirectories; There can be multiple directories.
- of type
f: plain file, so a directory like
./foo.cppis not found (it is of type
- matching the shell glob expression
'*.cpp'- which needs to be quoted, so the shell does not expand it before
findit even sees.
- which have a modification time (
-m...) up to (
-) 5 minutes (
- and shows the details similar to a
-mmin selects by modification time in minutes,
-mtime would select by modification time in days.
-mmin -5 selects files changed in the last 5 minutes,
-mmin 5 selects for changed 5 minutes ago,
-mmin +5 for more than 5 minutes
-newer otherfile compares to the age of another file
-iname '*.cpp' would also match
-ls shows file details like modification time. To get only filenames, leave it out.
That's a short summary, there are many more useful options - see