Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort files by modification time 1

Status
Not open for further replies.

vlz

IS-IT--Management
Aug 11, 2002
56
0
0
IL
Hi,
I'd like to sort regular files by modification time that resides in directory tree.
Is this command correct?
find /path/to/dir -type f | xargs ls -ltr

Thanks in advance,
Vadim
 
Probably, but it will list the files in date order by directory which might not be exactly what you require?
 
Yes I need files from all dir tree sorted as one list.
Do you have another solution?
 
I disagree, that is the correct command to do this, the only problem however is that if there are enough files to require multiple ls -ltr commands, each of those will be sorted individually.

I was thinking of something like a combination of these two commands to get around that...

[tt]# files older than 6 months
find . -type f | xargs ls -l | awk '!($8 ~ /:/)' | sort -k 8,8n -k 6,6M -k 7,7n > /tmp/sorted
# files newer than 6 months
find . -type f | xargs ls -l | awk '$8 ~ /:/' | sort -k 6,6M -k 7,7n -k 8,8n >> /tmp/sorted[/tt]

... the only problem being that if it was February, for example, you would still have files from the previous year listed with timestamps and they would be sorted incorrectly by the previous command, so it gets complicated...

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top