Want to sort my list of files according to date using Unix

0

My list of files is like ...

Oct 13 03:50 TEST_j002_26047.trc
Oct 11 17:10 TEST_j001_26047.trc
Oct 10 10:43 TEST_j000_6096.trc
Oct 12 02:52 TEST_j001_26048.trc

I want my output in a sorted way according to date:

Oct 10 10:43 TEST_j000_6096.trc
Oct 11 17:10 TEST_j001_26047.trc
Oct 12 02:52 TEST_j001_26048.trc
Oct 13 03:50 TEST_j002_26047.trc

Vivek varshney

Posted 2017-10-17T07:06:28.630

Reputation: 11

ls -rt not enough? – chingNotCHing – 2017-10-17T07:15:04.460

This is the natural sort order. – Aaron Copley – 2017-10-17T07:15:26.543

Answers

1

Try ls -lt or ls -ltr.

From the documentation of ls

   -l     use a long listing format
   -t     sort by modification time, newest first
   -r, --reverse
          reverse order while sorting

Xavier

Posted 2017-10-17T07:06:28.630

Reputation: 11

0

In what context?  If you just want to list them chronologically, use ls -tr.  The -t option specifies that files should be sorted by modification date/time.  In a dubious design decision, the default is newest first.  -r reverses that, putting the most recent files last.

If you want a glob (e.g., * or *.trc) to do this, is becomes trickier.

G-Man Says 'Reinstate Monica'

Posted 2017-10-17T07:06:28.630

Reputation: 6 509