Jump to content
Sign in to follow this  
Apoc

find command not working as expected [solved]

Recommended Posts

all,

 

i ahve the following command:

 

for archivefile in $(find ${LOGDIR} -type f -mtime +5 -name "WH*" )
do
   echo $archivefile
done

 

This lists all files beginning with WH and older than 5 days. This works fine. Now i have created a similar script:

 

for archivefile in $(find ${LOGDIR} -type f -mtime +5  -name "WH*" -o -name "D*" -o -name "0*")
do
  echo $archivefile
done

 

this does not work it will list all the files WH older than 5 days but will list all files beginning with D and 0 regardless of how old they are.. what am i doing wrong?

 

do i need the -mtime between each -o or is there an easier way??

 

ta.

Edited by Apoc

Share this post


Link to post
Share on other sites

i am not sure so i will stab at it.

 

why not use an and operator to find? you will have to figure out the sequence they are evaluated but i am suggesting to the likes of

 

-m +5 -a ( -name "" -o -name "" -o ...)

 

 

or wait till one of the cli junkies arrive. :)

 

ciao!

Share this post


Link to post
Share on other sites

I'm sure aru will have the correct answer, but my guess is it needs to be this:

 

for archivefile in $(find ${LOGDIR} -type f -mtime +5 -name "WH*" -o -type f -mtime +5 -name "D*" -o --type f -mtime +5 name "0*")

Share this post


Link to post
Share on other sites
I'm sure aru will have the correct answer, but my guess is it needs to be this:

 

for archivefile in $(find ${LOGDIR} -type f -mtime +5  -name "WH*" -o -type f -mtime +5 -name "D*" -o --type f -mtime +5 name "0*")

 

They both seemed to work but i have used the above example so others in my department can see whats happening.

 

Thanks.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...