Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

-atime any pitfalls to using it to find out last time file accessed?

I have the below which I ran to find files older then 90 days but my results don't seem accurate (from glancing at output file)?

find / -type f -name "*.jpg" -o -name "*.jpe" -o -name "*.JPE" -o -name "*.JPG" -o -name "*.MOV" -o -name "*.mov" -o -name "*.mpg" -o -name "*.MPG" -o -name "*.mpeg" -o -name "*.mp3" -o -name "*.MP3" -o -name "*.mp4" -o -name "*.MP4" -o -name "*.gif" -o -name "*.GIF" -o -name "*.zip" -o -name "*.flv" -o -name "*.fla" -o -name "*.png" -o -name "*.PNG" -o -name "*.pdf" -o -name "*.PDF" -o -name "*.swf" -o -name "*.SWF" -o -name "*.wma" -o -name "*.WMA" -o -name "*.wmv" -o -name "*.WMV" -o -name "*.wav" -o -name "*.WAV" -o -name "*.avi" -o -name "*.AVI" -o -name "*.bmp" -o -name "*.BMP" -atime +90 > oldfiles.txt


Can anyone see any issues with this?
Avatar of sunnycoder
sunnycoder
Flag of India image

Hi 894359,

Command looks good .. why do you think this is not right? What are the inconsistencies in the result?

Cheers!
sunnycoder
> -name "*.BMP" -atime +90
are connected with -and by default. And 'and' operator is stroneger than 'or'. Therefore the '-atime +90' applies to *.BMP files only. Also I suggest You to use single quotes instead doubles.
find / -type f -a \( -name '*.jpg' -o ...... \) -a -atime +90 # is it better?

Avatar of MJ

ASKER

Hi ravenpl.. are you saying that my find only applies  the -aname  +90 to bmps andwill list all other file extentions listed?

So it should look somewhat like this? Confused by the two additional  "-a" added also????

find / -type f -a \(-name '*.jpg' -o -name '*.jpe' -o -name '*.JPE' -o -name '*.JPG' -o -name '*.MOV' -o -name '*.mov' -o -name '*.mpg' -o -name '*.MPG' -o -name '*.mpeg' -o -name '*.mp3' -o -name '*.MP3' -o -name '*.mp4' -o -name '*.MP4' -o -name '*.gif' -o -name '*.GIF' -o -name '*.zip' -o -name '*.flv' -o -name '*.fla' -o -name '*.png' -o -name '*.PNG' -o -name '*.pdf' -o -name '*.PDF' -o -name '*.swf' -o -name '*.SWF' -o -name '*.wma' -o -name '*.WMA' -o -name '*.wmv' -o -name '*.WMV' -o -name '*.wav' -o -name '*.WAV' -o -name '*.avi' -o -name '*.AVI' -o -name '*.bmp' -o -name '*.BMP'\) -a  -atime +90 > oldfiles.txt
That's what I'm suggesting. Also '-type f' applied to '*.jpg' only ;)
-o == OR, -a == AND # it just reads better
Avatar of yuzh
yuzh

I suggest you to use "-mtime" or "-ctime" instead of "-atime".  The  access  time  of directories in path is changed by the  find command itself.


man find
to learn more deatils
> I suggest you to use "-mtime" or "-ctime" instead of "-atime".  The  access  time  of directories in path is changed by the  find command itself.
Only for directories. For files it stays untouched. stat(filename) does not update atime.
Avatar of MJ

ASKER

Not following what you mean here/

Also '-type f' applied to '*.jpg' only ;)
-o == OR, -a == AND # it just reads better
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial