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

migrated from May 30 '10 at 19:58

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

ls -t

or (for reverse, most recent at bottom):

ls -tr

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

  • 286
    ls -halt is for human readable, show hidden, print details, sort by date. – Evgeni Sergeev Oct 1 '13 at 5:24
  • 5
    In case anyone's wondering, both the -t and -r arguments are specified in the section about ls in the POSIX standard, so should be compatible across Unices. – Mark Amery Oct 27 '15 at 12:09
  • 4
    ls -llt for showing date-timestamp along with sorting – Harshul Pandav Sep 26 '16 at 20:01
  • 4
    Yes it is possible – Ashraf.Shk786 Feb 20 '17 at 13:09
  • 3
    @EvgeniSergeev DONT MEMORISE ls -halt a simple mistype may cause your server to crash! – Isaac Jul 9 '17 at 21:43

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

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.

  • 13
    You can also call source /etc/bashrc if you want to add it to your repertoire while running. – cwallenpoole Feb 11 '15 at 7:57
  • 1
    You can also add it in ~/.bash_aliases just for your user (one can create the file if it doesn't exist already – Dinei Apr 24 at 1:23

I use sometime this:

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


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

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

... or now, with recent version of GNU find:

find . -type f -mmin -5 -exec ls -ltr {} +

... and even for not limiting to files:

find . -mmin -5 -exec ls -ltrd {} +

(note the -d switch to ls for not displaying content of directories)

  • By recursively you mean it lists all files in subdirectories, doesn't ls already have a switch to do that? – jiggunjer May 14 '15 at 16:28
  • @jiggunjer ls -Rltr will sort by dir, then by dates, find -type f -mmin -5 -exec ls -ltr {} + will just print files modified in last 5 minutes, sorted by date, regardless of directory tree! – F. Hauri Dec 7 '16 at 18:08


alias lt='ls -Alhtr'

in $homedir/.bashrc

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

find / -ctime 3


For don't ignore entries starting with . and sort by date (newest first):

ls -at

For don't ignore entries starting with . and reverse sort by date (oldest first):

ls -art

For don't ignore entries starting with ., use a long listing format and sort by date (newest first):

ls -alt

For print human readable sizes, don't ignore entries starting with ., use a long listing format and sort by date (newest first) (@EvgeniSergeev note):

ls -halt

but be careful with the last one, because a simple mistype can cause a server crash... (@Isaac note)

To show 10 most recent sorted by date, I use something like this:

ls -t ~/Downloads | head -10

or to show oldest

ls -tr ~/Downloads | tail -10
  • it givls -t head -2 and ls -tr | tail -2 gives same result, option (-t/-tr) should be kept fixed and modified the tail/head or vice verse, modifing both is like modyfing nothing – DDS Jun 27 at 16:09

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.

protected by Nifle Aug 16 '12 at 18:15

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

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