Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I sort the output of ls by last modified date?

share|improve this question

migrated from stackoverflow.com May 30 '10 at 19:58

This question came from our site for professional and enthusiast programmers.

95  
You guys need to chill - the answer isn't there on Google without digging around, and there isn't to my knowledge a duplicate on SO. Question asked, question answered, move on. –  nearly_lunchtime Apr 9 '09 at 13:26
10  
Ehm... There actually is an answer on Google, it's right there in the ls man page. –  Tom Wijsman Aug 28 '11 at 14:55
    
I think Tom Wijsman's comment is a perfectly valid answer. –  Vorac Sep 12 '12 at 6:02
4  
What's ironic is that people who suggest "googling it" have very little understand of how websites or search engines work. It's like they have no idea that they are on a website now, and google points/indexes to their idiotic circular logic as well as the answer that is going to be posted right under them anyway. –  Zombies Jun 8 at 16:16
2  
Fortunately the answer is there on google now, brought me right to this page with the information I needed. –  Jason Goemaat Jun 26 at 11:53

7 Answers 7

ls -t

or (for reverse, most recent at bottom):

ls -tr

The ls man page describes this in more details, and lists other options.

share|improve this answer
19  
ls -halt is for human readable, show hidden, print details, sort by date. –  Evgeni Sergeev Oct 1 '13 at 5:24

Try this: ls -ltr. It will give you the recent to the end of the list

share|improve this answer

For a complete answer here is what I use: ls -lrth

Put this in your startup script /etc/bashrc and assign an alias like this: alias l='ls -lrth' Restart your terminal and you should be able to type l and see a long list of files.

share|improve this answer

Add:

alias lt='ls -Alhtr'

in $homedir/.bashrc

share|improve this answer

I use sometime this:

find . -type f -mmin -5 -print0 | xargs -0 /bin/ls -tr

or

find . -type f -mmin -5 -print0 | xargs -0 /bin/ls -ltr

to look recursively about which files was modified in last 5 minutes.

share|improve this answer

Find all files on filesystem that were modified maximally 3 * 24 hours (3 days) ago till now:

find / -ctime 3
share|improve this answer

Using only very basic unix commands:

ls -nl | sort -k 8,8n -k 6,6M

This worked on Linux; column 8 is "n" (numeric), column 6 is "M", month.

I'm new at sort, so this answer could probably be improved. Not to mention, it needs additional options to ls and sort to use exact timestamps, but not everyone will need this.

share|improve this answer

protected by Nifle Aug 16 '12 at 18:15

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?