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.cpp is not found (it is of type d)
  • matching the shell glob expression '*.cpp' - which needs to be quoted, so the shell does not expand it before find 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.

|improve this answer|||||
  • @VolkerSiegel what's the difference ? when i write with type and without type finding cpp file... – qwerty Oct 1 '14 at 16:01
  • Without -type f you would also find directories like ./foo.cpp/! – Volker Siegel Oct 1 '14 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.