1753505 Members
6512 Online
108794 Solutions
New Discussion юеВ

Re: Find acting peculiar

 
SOLVED
Go to solution
Rinky
Advisor

Find acting peculiar

Hi all,

The find command is acting in a peculiar way. I want to find all the files newer than file D.
ll -rt
total 0
Aug 19 12:11 D
Aug 20 11:29 C
Aug 21 13:38 A
Aug 21 13:38 B

find . -newer D
.
./A
./B
./C

I was expecting the output as
C
A
B !!!!

Could anyone please help ??
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Find acting peculiar

Hi Rinky:

The output is as expected. It shows relative file paths and the order is as the entities exist in the *directory* being searched.

Thus, if you want them to appear in increasing "newness" of their modification timestamp, do:

# find . -newer D -exec ls -drlt {} +

If it is only *files* you want, add the '-type f' :

# find . -type f -newer D -exec ls -drlt {} +

The 'ls -drlt' orders your output.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Find acting peculiar

Hi (again) Rinky:

Please don't forget to evaulate the answers you receive. See:

http://forums12.itrc.hp.com/service/forums/helptips.do?#28

In fact, a corollary question of yours on 'find' needs to be scored too:

http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1254376

By scoring the responses you receive, future readers of your threads can better evaulate what helped solve *your* question.

Regards!

...JRF...
TTr
Honored Contributor

Re: Find acting peculiar

It is working as expected. It found all the files that are newer than D. The find command does not sort the files by date, it displays them as it finds them while traversing the directory trees and directory listings. The files appear in the order they were created in the directory listing. That order is displayed by the "ls -e" command. If you use the "ls -e" command you will see the files in the same order as shown by the find command.
Rinky
Advisor

Re: Find acting peculiar

Thank u so much James and TTr
Rinky
Advisor

Re: Find acting peculiar

Points assigned :)