Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

This chapter is from the book

This chapter is from the book

Sort Contents by Date and Time

ls -t

Letters are great, but sometimes you need to sort a directory’s contents by date and time. To do so, use -t (or --sort=time) along with -l; to reverse the sort, use -tr (or --sort=time --reverse) along with -l. Using the reverse sort can be pretty handy—the newer stuff ends up at the bottom, which is easier to see, because that’s where your prompt will be when the command finishes!

$ ls -latr ~/
-rw-------    1 scott scott  8800 2015-10-18 19:55 .bash_history
drwx------   15 scott scott  1280 2015-10-18 20:07 .opera
drwx------    2 scott scott    80 2015-10-18 20:07 .gconfd
drwxr-xr-x    2 scott scott   432 2015-10-18 23:11 .qt
drwxr-xr-x  116 scott scott  5680 2015-10-18 23:11 .
drwx------    3 scott scott   368 2015-10-18 23:12 .gnupg
drwxr-xr-x   12 scott scott  2760 2015-10-18 23:14 bin
drwx------    4 scott scott   168 2015-10-19 00:13 .Skype
[list condensed and edited due to length]

All of these items except the last one were modified on the same day; the last one would have been first if you weren’t using the -r option and thereby reversing the results.

  • + Share This
  • 🔖 Save To Your Account