Solved

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

Posted on 2006-10-22
8
250 Views
Last Modified: 2010-05-19
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?
0
Comment
Question by:894359
8 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17783046
Hi 894359,

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

Cheers!
sunnycoder
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17783301
> -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?

0
 

Author Comment

by:894359
ID: 17784645
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
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17786650
That's what I'm suggesting. Also '-type f' applied to '*.jpg' only ;)
-o == OR, -a == AND # it just reads better
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 38

Expert Comment

by:yuzh
ID: 17786990
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
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17787010
> 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.
0
 

Author Comment

by:894359
ID: 17792120
Not following what you mean here/

Also '-type f' applied to '*.jpg' only ;)
-o == OR, -a == AND # it just reads better
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 17793716
> Not following what you mean here
Then focus

You can type
find / -type f -name '*.jpg' -name '*.JPG' # which means same as
find / -type f -a -name '*.jpg' -a -name '*.JPG' # because -a means AND, and it's default operator(when no operator)
also, AND has higher precedence, so
find / -type f -name '*.jpg' -name '*.JPG' -o -type d #means same as
find / \( -type f -name '*.jpg' -name '*.JPG' \) -o -type d # where I assume You know what parens do?

So in Your first example parens and -a are like
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 \)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now