Loading...
General

Sorting Files By Date and Time

There is more than one way to display files that are sorted by date, but I prefer to use the ll command to list the files, then the r to list them in reverse order and the t flag to sort them by the time.

So, we start out with a list of files such as this.
# ll
total 332
drwxr-xr-x 2 user user 4096 Nov 27 17:29 cgi-bin
-rwxr-xr-x 1 user user 397 May 25 2008 index.php
-rwxr-xr-x 1 user user 15410 Dec 6 2008 license.txt
-rwxr-xr-x 1 user user 9122 Jul 22 2010 readme.html
-rwxr-xr-x 1 user user 4391 Apr 19 2010 wp-activate.php
drwxr-xr-x 7 user user 4096 Jul 29 2010 wp-admin
-rwxr-xr-x 1 user user 40284 Jul 25 2010 wp-app.php
-rwxr-xr-x 1 user user 220 Oct 14 2008 wp-atom.php
-rwxr-xr-x 1 user user 274 May 25 2008 wp-blog-header.php
-rwxr-xr-x 1 user user 3926 May 6 2010 wp-comments-post.php
-rwxr-xr-x 1 user user 238 Oct 14 2008 wp-commentsrss2.php
-rwxr-xr-x 1 user user 3494 Nov 27 17:32 wp-config.php
-rwxr-xr-x 1 user user 3173 Oct 6 04:31 wp-config-sample.php
drwxr-xr-x 6 user user 4096 Nov 28 23:03 wp-content
-rwxr-xr-x 1 user user 1255 Mar 16 2010 wp-cron.php
-rwxr-xr-x 1 user user 240 Apr 19 2010 wp-feed.php
drwxr-xr-x 7 user user 4096 Jul 29 2010 wp-includes
-rwxr-xr-x 1 user user 2002 Mar 18 2010 wp-links-opml.php
-rwxr-xr-x 1 user user 2441 Feb 28 2010 wp-load.php
-rwxr-xr-x 1 user user 26059 Jun 1 2010 wp-login.php
-rwxr-xr-x 1 user user 7774 May 25 2010 wp-mail.php
-rwxr-xr-x 1 user user 487 Apr 20 2009 wp-pass.php
-rwxr-xr-x 1 user user 218 Oct 14 2008 wp-rdf.php
-rwxr-xr-x 1 user user 316 May 25 2008 wp-register.php
-rwxr-xr-x 1 user user 220 Oct 14 2008 wp-rss2.php
-rwxr-xr-x 1 user user 218 Oct 14 2008 wp-rss.php
-rwxr-xr-x 1 user user 9177 May 2 2010 wp-settings.php
-rwxr-xr-x 1 user user 18695 Jul 21 2010 wp-signup.php
-rwxr-xr-x 1 user user 3702 Feb 24 2010 wp-trackback.php
-rwxr-xr-x 1 user user 94184 Jul 14 2010 xmlrpc.php

Then, using ll -rt, you will show the files like this, in reverse order of date and time.
# ll -rt
total 332
-rwxr-xr-x 1 user user 316 May 25 2008 wp-register.php
-rwxr-xr-x 1 user user 274 May 25 2008 wp-blog-header.php
-rwxr-xr-x 1 user user 397 May 25 2008 index.php
-rwxr-xr-x 1 user user 218 Oct 14 2008 wp-rss.php
-rwxr-xr-x 1 user user 220 Oct 14 2008 wp-rss2.php
-rwxr-xr-x 1 user user 218 Oct 14 2008 wp-rdf.php
-rwxr-xr-x 1 user user 238 Oct 14 2008 wp-commentsrss2.php
-rwxr-xr-x 1 user user 220 Oct 14 2008 wp-atom.php
-rwxr-xr-x 1 user user 15410 Dec 6 2008 license.txt
-rwxr-xr-x 1 user user 487 Apr 20 2009 wp-pass.php
-rwxr-xr-x 1 user user 3702 Feb 24 2010 wp-trackback.php
-rwxr-xr-x 1 user user 2441 Feb 28 2010 wp-load.php
-rwxr-xr-x 1 user user 1255 Mar 16 2010 wp-cron.php
-rwxr-xr-x 1 user user 2002 Mar 18 2010 wp-links-opml.php
-rwxr-xr-x 1 user user 4391 Apr 19 2010 wp-activate.php
-rwxr-xr-x 1 user user 240 Apr 19 2010 wp-feed.php
-rwxr-xr-x 1 user user 9177 May 2 2010 wp-settings.php
-rwxr-xr-x 1 user user 3926 May 6 2010 wp-comments-post.php
-rwxr-xr-x 1 user user 7774 May 25 2010 wp-mail.php
-rwxr-xr-x 1 user user 26059 Jun 1 2010 wp-login.php
-rwxr-xr-x 1 user user 94184 Jul 14 2010 xmlrpc.php
-rwxr-xr-x 1 user user 18695 Jul 21 2010 wp-signup.php
-rwxr-xr-x 1 user user 9122 Jul 22 2010 readme.html
-rwxr-xr-x 1 user user 40284 Jul 25 2010 wp-app.php
drwxr-xr-x 7 user user 4096 Jul 29 2010 wp-includes
drwxr-xr-x 7 user user 4096 Jul 29 2010 wp-admin
-rwxr-xr-x 1 user user 3173 Oct 6 04:31 wp-config-sample.php
drwxr-xr-x 2 user user 4096 Nov 27 17:29 cgi-bin
-rwxr-xr-x 1 user user 3494 Nov 27 17:32 wp-config.php
drwxr-xr-x 6 user user 4096 Nov 28 23:03 wp-content

or you can leave out the r to list them in order of newest to oldest.
# ll -t
total 332
drwxr-xr-x 6 user user 4096 Nov 28 23:03 wp-content
-rwxr-xr-x 1 user user 3494 Nov 27 17:32 wp-config.php
drwxr-xr-x 2 user user 4096 Nov 27 17:29 cgi-bin
-rwxr-xr-x 1 user user 3173 Oct 6 04:31 wp-config-sample.php
drwxr-xr-x 7 user user 4096 Jul 29 2010 wp-admin
drwxr-xr-x 7 user user 4096 Jul 29 2010 wp-includes
-rwxr-xr-x 1 user user 40284 Jul 25 2010 wp-app.php
-rwxr-xr-x 1 user user 9122 Jul 22 2010 readme.html
-rwxr-xr-x 1 user user 18695 Jul 21 2010 wp-signup.php
-rwxr-xr-x 1 user user 94184 Jul 14 2010 xmlrpc.php
-rwxr-xr-x 1 user user 26059 Jun 1 2010 wp-login.php
-rwxr-xr-x 1 user user 7774 May 25 2010 wp-mail.php
-rwxr-xr-x 1 user user 3926 May 6 2010 wp-comments-post.php
-rwxr-xr-x 1 user user 9177 May 2 2010 wp-settings.php
-rwxr-xr-x 1 user user 240 Apr 19 2010 wp-feed.php
-rwxr-xr-x 1 user user 4391 Apr 19 2010 wp-activate.php
-rwxr-xr-x 1 user user 2002 Mar 18 2010 wp-links-opml.php
-rwxr-xr-x 1 user user 1255 Mar 16 2010 wp-cron.php
-rwxr-xr-x 1 user user 2441 Feb 28 2010 wp-load.php
-rwxr-xr-x 1 user user 3702 Feb 24 2010 wp-trackback.php
-rwxr-xr-x 1 user user 487 Apr 20 2009 wp-pass.php
-rwxr-xr-x 1 user user 15410 Dec 6 2008 license.txt
-rwxr-xr-x 1 user user 220 Oct 14 2008 wp-atom.php
-rwxr-xr-x 1 user user 238 Oct 14 2008 wp-commentsrss2.php
-rwxr-xr-x 1 user user 218 Oct 14 2008 wp-rdf.php
-rwxr-xr-x 1 user user 220 Oct 14 2008 wp-rss2.php
-rwxr-xr-x 1 user user 218 Oct 14 2008 wp-rss.php
-rwxr-xr-x 1 user user 397 May 25 2008 index.php
-rwxr-xr-x 1 user user 274 May 25 2008 wp-blog-header.php
-rwxr-xr-x 1 user user 316 May 25 2008 wp-register.php

I also like to add in an awk command if I am just looking for the dates to make it easier to read.

# ll -rt |awk '{print $6, $7, $8, $9}'

May 25 2008 wp-register.php
May 25 2008 wp-blog-header.php
May 25 2008 index.php
Oct 14 2008 wp-rss.php
Oct 14 2008 wp-rss2.php
Oct 14 2008 wp-rdf.php
Oct 14 2008 wp-commentsrss2.php
Oct 14 2008 wp-atom.php
Dec 6 2008 license.txt
Apr 20 2009 wp-pass.php
Feb 24 2010 wp-trackback.php
Feb 28 2010 wp-load.php
Mar 16 2010 wp-cron.php
Mar 18 2010 wp-links-opml.php
Apr 19 2010 wp-activate.php
Apr 19 2010 wp-feed.php
May 2 2010 wp-settings.php
May 6 2010 wp-comments-post.php
May 25 2010 wp-mail.php
Jun 1 2010 wp-login.php
Jul 14 2010 xmlrpc.php
Jul 21 2010 wp-signup.php
Jul 22 2010 readme.html
Jul 25 2010 wp-app.php
Jul 29 2010 wp-includes
Jul 29 2010 wp-admin
Oct 6 04:31 wp-config-sample.php
Nov 27 17:29 cgi-bin
Nov 27 17:32 wp-config.php
Nov 28 23:03 wp-content

If your machine does not have the ll command, you can achieve the same thing by using ls -lrt, or ls -lt.

Popular Posts
  • No Popular Post Available
One comment
Leave a Reply

Your email address will not be published. Required fields are marked *

*