Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • are you looking for only modified files? Or are you looking at all files?
    – Keltari
    Commented Feb 2, 2013 at 17:25
  • 1
    I'm sure PowerShell can do this far more easily than batch, but if you absolutely must use the latter... Try dir /a-d /o-d /tw /s (show files only, order by date descending, use last write time for sorting, recurse into subdirs). However this will list all files. To limit the list to n latest modified files only, use dbenham's brilliant solution here.
    – Karan
    Commented Feb 2, 2013 at 17:43
  • A couple of comments on the Linux command: (1) Instead of -exec, you might want to consider xargs. (2) If you, as you say, want to sort an entire directory (sub)tree by modification date (and then look at the newest N), then what you have is reasonable. But if you can get the information you need by finding all files modified in the last N days, look at find … -mtime …. Commented Feb 2, 2013 at 20:41
  • 2
    To add to my previous comment, you can also look into forfiles /s /d +<date>.
    – Karan
    Commented Feb 2, 2013 at 23:22