LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-28-2010, 05:30 AM   #1
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Rep: Reputation: 15
Sorting in aggregate rather than tree fashion with 'ls -Rt'?


The command:
Code:
ls -lRt
Shows a recusrive listing, and sorts by modification time. But this in in tree fashion, where it first lists the contents of the current folder sorted by time, and then the contents of each child folder sorted by time.

How would one accomplish this type of sort, but with an aggregate listing - all items recursively sorted together, rather than by individual folder?
 
Old 04-28-2010, 06:10 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Code:
ls -lR | sed -n '/^-/p' | tr -s ' ' | sort -t' ' -k6
Code:
...
-rw-r--r-- 1 jschiwal jschiwal 18652832 2010-03-05 23:19 RB141.mp3                                                                     
-rw-r--r-- 1 jschiwal jschiwal 25038447 2010-03-05 23:19 RB140.mp3                                                                     
-rw-r--r-- 1 jschiwal jschiwal 144802 2010-03-06 16:55 b4fcad4341906e79f3f78f4507b5a125.jpg                                            
-rw-r--r-- 1 jschiwal jschiwal 144475 2010-03-07 11:53 708bb31db3a111513d6fdb0e7f6ca6c5.jpg                                            
-rw-r--r-- 1 jschiwal jschiwal 268350909 2010-03-07 20:54 glp086.mp3                                                                   
-rw-r--r-- 1 jschiwal jschiwal 357268920 2010-03-07 20:52 glp093.mp3                                                                   
-rw-r--r-- 1 jschiwal jschiwal 460174695 2010-03-07 20:54 glp089.mp3                                                                   
-rw-r--r-- 1 jschiwal jschiwal 530745787 2010-03-07 20:54 glp088.mp3                                                                   
-rw-r--r-- 1 jschiwal jschiwal 34945464 2010-03-08 21:18 TheTechieGeek_058.mp3                               
...
Note however that the directory part of the path is lost.

also consider using "find . -type f -ls" to produce the long listing. Another advantage of using find is that you could use -printf instead of -ls and control what information about the file you want displayed, and in what order and the format of the line.

Last edited by jschiwal; 04-28-2010 at 06:13 AM.
 
Old 04-28-2010, 07:02 AM   #3
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
Code:
ls -lR | sed -n '/^-/p' | tr -s ' ' | sort -t' ' -k6
Thanks. This however doesn't seem to sort by date properly for me though - for instance, the following subset of a listing is out of order:
Code:
-rw-r--r-- 1 forum forum 82975 Aug 8 2009 sigpic11285_2.gif
-rw-r--r-- 1 forum forum 1303 Aug 9 2005 arcade.css
-rw-r--r-- 1 forum forum 4690 Aug 9 2005 arcade.js
-rw-r--r-- 1 forum forum 8832 Aug 9 2008 avatar10110_2.gif
-rw-r--r-- 1 forum forum 11406 Aug 9 2008 avatar9103_2.gif
 
Old 04-28-2010, 03:29 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
My "ls -lR" printed out the date in the form yyyy-mm-dd. There is a -M option to sort to Sort by month.
But this is only for the 8th field. You can have more than one key argument and add an option. -k6M will sort the field by the month, but you want the primary key to be 8th field since it is the year.

I think `sort -k8,8n -k6,6M -k7,7n' will work if all the dates are of the form "Month dd yyyy".

Also look at the --time-style option for ls. Using the find command as well, there are various ways you can have the date printed. Since the form of the date listed can depend on your locale, and may vary in form for very recent files, I would recommend controlling the format of the date listed and using a form that is easily sorted. I would also recommend using `find' instead of 'ls -R' t

Last edited by jschiwal; 04-28-2010 at 03:30 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Aggregate Error in c++ using g++ compiler flanders Programming 2 04-08-2009 07:40 PM
How can I make my aggregator actually *aggregate*? Chriswaterguy Linux - Software 2 04-16-2008 01:48 AM
c++ initialization lists (error, non aggregate type) Que? byteframe Programming 2 12-15-2005 07:58 PM
the bible = the tree of the knowledge of good and evil () Jesus = the tree of life Michael111 General 2 04-14-2004 05:28 PM


All times are GMT -5. The time now is 04:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration