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.

I want to sort only files by update dates including sub-directories.

I found out ls -lrtR | grep ^-. but it doesn't seem to sort by update dates.

And I need to save this list into a file. Is it possible?

Apr 01 2010  InsideDoosanServiceImpl.class  // in A directory
Apr 08 2010  MainController.class  // in B directory
Apr 07 2010  RecommendController.class  // in B directory
Apr 01 2010  MainDao.class  // in B directory

I mean the whole list is not ordered by date, but first ordered by folder, and ordered by date.

I want a list first ordered by date including all sub-directories.

share|improve this question
add comment

migrated from stackoverflow.com Jan 18 '12 at 12:46

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

2 Answers

up vote 2 down vote accepted

I am not sure what exactly do you mean by update dates, but you are using -r option which according to man does this -

-r Reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size

I think this should be good enough for you if you need files sorted by time.

ls -lRt

If you don't need all the other stuff listed by ls then you can use -

ls -1Rt

To capture the result in a file, you can use the redirection operator > and give a file name. So you can do something like this -

ls -lRt > sortedfile.list

Update:

find . -type f -exec ls -lt {} +
share|improve this answer
    
I mean the last time a file was modified :) –  Deckard Jan 18 '12 at 6:35
    
Sort result is ordered by folder and date. I want to sort by date and folder.. is it possible? –  Deckard Jan 18 '12 at 6:59
    
Sorry, can you please show me some output? I didn't quite follow the sorting of folder if you used ls -lrt. –  JS웃 Jan 18 '12 at 7:11
    
//Jaypal Singh, I updated my output to my quiestion ↑ :). I really hope you understand it and sorry for my bad English. –  Deckard Jan 18 '12 at 7:25
    
No worries, I have added an alternative. Hope that helps. –  JS웃 Jan 18 '12 at 7:33
show 5 more comments

With ls, -R will recurse directories and -t will sort by modification. However, it traverses directories recursively and applies -t to each directory. It doesn't accumulate all files from all directories and then sort. (As far as I understand, the latter is what you want)

With gnu find(1) you can specify the format of output to include the number of seconds since epoch and the filename, then you can pipe this to sort(1).

find . -type f -printf "%T@ %f\n" | sort -n > out.txt
share|improve this answer
    
Yea GNU find does help. But OP works on AIX machines so GNU find wasn't available to him. –  JS웃 Jan 18 '12 at 7:52
add comment

Your Answer

 
discard

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