Let's say I want to find files base from the last given modified days and sort list base from the latest modified date.


find /path/to/files -mtime -15 | xargs -d '\n' -r ls -t

Output: note: I will just indicate the modified date in the filename to show their modified date


Then I want to get the those files with the latest modified date but the same day

E.g. Final output: This is taken from the result of the first output.

  • The Best would ne to explain what you want to do clearly because i have read your question 3 times ans Im still unsure about what you want. Also as the question on the site should not be opinion base the phrasing : what is the Best way is rarely the Best way to ask here ;-) – Kiwy Apr 6 '18 at 8:21
  • @Kiwy, ok I'll remove it – WashichawbachaW Apr 6 '18 at 8:31
  • If you would have several files from March 26th should they show up in the result as well? If there is only one file modified on the most recent days but several files modified on a past day (e.g. March 28th in your sample) what should get shown? – nohillside Apr 6 '18 at 8:54
  • @patrix only show the files with the same latest day from the output of find /path/to/files -mtime -15 | xargs -d '\n' -r ls -t – WashichawbachaW Apr 6 '18 at 9:16

This will do it:

FIND_PATH='/path/to/files'; find "$FIND_PATH" -newermt $(find "$FIND_PATH" -printf '%TY-%Tm-%Td\n' | sort | tail -1)

The "inner" find will print all modification dates in yyyy-mm-dd format and print only the newest (| sort | tail -1).

The "outer" find will only find files with this date.


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.