LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   List all regular files in the disk sorted by modification time. (http://www.linuxquestions.org/questions/slackware-14/list-all-regular-files-in-the-disk-sorted-by-modification-time-4175483575/)

stf92 11-06-2013 05:45 AM

List all regular files in the disk sorted by modification time.
 
Hi: Let be the set of all regular files on my linux partition. I'd like
to list its elements in chronological order, with respect to modification
time. Any simple way to do it?

e5150 11-06-2013 05:52 AM

Code:

find /path -xdev -type f -printf "%Ts %p\n" | sort -n | awk '{print $2}'
will sort from old to new, if you want recently modified files first, add the "-r" argument to the sort command, or pipe the result to `tac`.

stf92 11-06-2013 06:48 AM

Thanks for your reply. But tell me, how could I have the same list, but with a second column displaying the modification date?

e5150 11-06-2013 07:26 AM

Technically, you could just remove the "| awk '{print $2}'", then it would print the "unix-time" (seconds since midnight at 1st Jan 1970). But I'm guessing you want something human readable. This should work
Code:

find ~/tmp -type f -printf "%TY-%Tm-%Td %TH:%TM:%TS %p\n" | sort
by printing "YYYY-MM-DD HH:MM:SS.... /path/to/file" so a lexicographical ordering happens to also be chronological.
You can change the time format to your liking (see `man 3 strftime`), but be careful with non-numerical time variables (eg. "03:16 AM" < "03:16 PM", but "Friday" < "Monday").

stf92 11-06-2013 08:43 AM

Terrific! Thanks a lot.


All times are GMT -5. The time now is 09:22 PM.