How we will find more accurately all .cpp
files in the users home directory that were modified no more than 5 minutes ago?
1 Answer
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.cpp
is not found (it is of typed
) - matching the shell glob expression
'*.cpp'
- which needs to be quoted, so the shell does not expand it beforefind
it even sees. - which have a modification time (
-m...
) up to (-
) 5 minutes (-...min
) ago. - and shows the details similar to a
ls -l
-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 foo.CPP
and bar.cPp
-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 man find
.
-
@VolkerSiegel what's the difference ? when i write with type and without type finding cpp file...– qwertyOct 1, 2014 at 16:01
-
Without
-type f
you would also find directories like./foo.cpp/
! Oct 1, 2014 at 16:02