Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Original:

Jan 23 2011 10:42 SOMETHING 2007.12.20.avi
Jun 26 2009 SOMETHING 2009.06.25.avi
Feb 12 2010 SOMETHING 2010.02.11.avi
Jan 29 2011 09:17 SOMETHING 2011.01.27.avi
Feb 11 2011 20:06 SOMETHING 2011.02.10.avi
Feb 27 2011 23:05 SOMETHING 2011.02.24.avi

Output:

Feb 27 2011 23:05 SOMETHING 2011.02.24.avi
Feb 11 2011 20:06 SOMETHING 2011.02.10.avi
Jan 29 2011 09:17 SOMETHING 2011.01.27.avi
Jan 23 2011 10:42 SOMETHING 2007.12.20.avi
Feb 12 2010 SOMETHING 2010.02.11.avi
Jun 26 2009 SOMETHING 2009.06.25.avi

How could I get the output where the newest file is at the top?

share|improve this question
1  
@user4724: how did yuo generate the list ? –  Iain Feb 28 '11 at 20:30
    
pastebin.com/raw.php?i=EGvaAidz –  LanceBaynes Feb 28 '11 at 21:20
    
@user4724: That doesn't generate the same type of outpout for me that you have - no matter as Gilles has the answer –  Iain Feb 28 '11 at 21:46
add comment

2 Answers

Is that a text file you're trying to sort, or are you trying to view a directory listing by date? For the latter, use the -t flag to ls. For the former, see in particular the -M flag to GNU sort, which sorts by three-letter month name abbreviations. The following command sorts by the 3rd, 1st, 2nd and 4th columns, treating the second sort key as a month name.

sort -k 3 -k 1M -k2 -k4 in.txt

Do consider always using Japanese/ISO style dates, always in the order YYYY-MM-DD-HH-MM-SS (i.e. most significant first, constant column width). This way sorting by date is identical to a lexicographic sort.

share|improve this answer
add comment

On most unices, ls has a -t option. From the man page of my Debian box:

-t sort by modification time

Try the following command:

$ ls -lt

share|improve this answer
    
i need it recursively, sorry –  LanceBaynes Feb 28 '11 at 21:21
    
+ls -lt will list a full directory, if 1 file changes in it. –  LanceBaynes Feb 28 '11 at 21:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.