1820695 Members
2408 Online
109627 Solutions
New Discussion юеВ

Sorting of files by date

 
Shahril M
Frequent Advisor

Sorting of files by date

Hi folks,

ls has the -t option to sort by date.
find allows me to list files anywhere below the specified path

So I used this combination to list all files by date, but it does not seem to work perfectly. Either this method is not be viable, or my command is wrong.

Is there a better way to achieve what I want?

# find /tmp -name "ATTRIB*"|xargs ll -rt|more

I attach a sample output. Note that it appears to begin correctly, with 2002, 2004 then current year files. It goes on to Sep by dates, then suddenly after Sep 22, it lists Aug files. Then you see more irregularities.

Any assistance is much appreciated.


Rgds,
Shahril
3 REPLIES 3
Shahril M
Frequent Advisor

Re: Sorting of files by date

It appears that my attachment did not go through after a preview.

Side-track: a bug with ITRC Forums?
Muthukumar_5
Honored Contributor

Re: Sorting of files by date

You are sorting with -t option ls. -t Sort by time modified (latest first) before sorting alphabetically. It will modify files based on modification time.

Time period in
drwxr-xr-x 4 root other 96 Apr 13 19:20 config

Apr 13 19:20 may be modified time or access time or changed time.

To sort based on changed time then,

# find /tmp -name "ATTRIB*"|xargs ls -lrc

By accessed time then,

# find /tmp -name "ATTRIB*"|xargs ls -lru

If you want to sort based on time in ls then we have to write a script do it.

hth.
Easy to suggest when don't know about the problem!
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Sorting of files by date

Your ll seems to be a alian for ls -l.

Try direclty this approach
ls -ltr
Vibhor Kumar Agarwal