Operating System - HP-UX
1833016 Members
2424 Online
110048 Solutions
New Discussion

Why command "ls -u" difference with "find -atime?"

 
akit3210
Occasional Advisor

Why command "ls -u" difference with "find -atime?"

I want to list last access file that more than 30 days. In this case command ls can't specific date, then I choose command find. but this result of 2 command difference. ls -lu is true. Why? or please suggest other statement.

Example of find command:
#find . -name "*.*" -atime +30 -exec ls -l {} \;
Example of ls command
#ls -lu

In same file show difference access time.

Thank you for every answer.
2 REPLIES 2
Matti_Kurkela
Honored Contributor

Re: Why command "ls -u" difference with "find -atime?"

Your command
#find . -name "*.*" -atime +30 -exec ls -l {} \;

is _selecting_ files to display according to access time, but then _displaying_ the modification time, because the ls command does not have the -u option here.

To get the _access_ times of files that haven't been accessed in 30 days, you would have to add the -u option:

#find . -name "*.*" -atime +30 -exec ls -lu {} \;

Also remember that for find, "-atime +30" actually means "accessed more than 30 complete days ago". If you run this now today (17th October on 09:00), it will choose the files accessed at or before 16th September 09:00.

Apparently the algorithm in "find" command counts the number of days, then discards the fractions before comparing to the target number.
MK
akit3210
Occasional Advisor

Re: Why command "ls -u" difference with "find -atime?"

Thank you very much Matti.

Very quickly response:

:)