Re: Semi-OT: Problems getting find to not recurse

2005-07-06 Thread Otto Moerbeek
On Wed, 6 Jul 2005, C. Bensend wrote:

 Hey folks,
 
OK, I think I've got the dunce hat on today, and I'm about to
 go crazy with this one.
 
I have a script on an OpenBSD 3.7-STABLE machine that does
 a find in a directory, and uses rm to remove files older than
 two days (where RETAIN = +2) :
 
 find /path/to/dir -type f -name \*.gz -mtime ${RETAIN} -exec rm {} \;
 
This directory has a subdir (a .ssh), and no matter what I
 do, I cannot get find to NOT recurse into this subdirectory.  I've
 tried using -path, ! -path, -maxdepth 0|1, and none of them seem
 to do what I want.  I only want find to examine the /path/to/dir
 directory, and not any subdirs.
 
I've been through the man page so many times, I can just about
 recite it.  Am I just missing something, or is this not possible?
 I'm guessing it's the former and I've just stared at it too long to
 see the obvious.

Something like this should work (compare some of th examples of the man
page):

find /path/to/dir -name .ssh -type d -prune -or \
-type f -name \*.gz -mtime ${RETAIN} -exec rm {} \;

-Otto



Re: Semi-OT: Problems getting find to not recurse

2005-07-06 Thread C. Bensend
 Something like this should work (compare some of th examples of the man
 page):

 find /path/to/dir -name .ssh -type d -prune -or \
   -type f -name \*.gz -mtime ${RETAIN} -exec rm {} \;

Thank you very much, Otto.  That works just fine.  It's greatly
appreciated!

Benny


-- 
I'd rather staple a skunk to my forehead and go to a trade show
for banjo makers.-- PHB's secretary,
 Dilbert, 07-2002



Re: Semi-OT: Problems getting find to not recurse

2005-07-06 Thread Matthias Kilian
On Wed, Jul 06, 2005 at 02:33:30PM -0500, C. Bensend wrote:
  find /path/to/dir -name .ssh -type d -prune -or \
  -type f -name \*.gz -mtime ${RETAIN} -exec rm {} \;
 
 Thank you very much, Otto.  That works just fine.  It's greatly
 appreciated!

Well, even if it helped, I can't reproduce your problem:

find /home/kili -maxdepth 1 -type f -name \* -mtime +1 -exec echo {} \; |
grep ssh

yields no output at all. [And of course, I *do* have a .ssh directory.]

Ciao,
Kili



Re: Semi-OT: Problems getting find to not recurse

2005-07-06 Thread Otto Moerbeek
On Wed, 6 Jul 2005, Matthias Kilian wrote:

 On Wed, Jul 06, 2005 at 02:33:30PM -0500, C. Bensend wrote:
   find /path/to/dir -name .ssh -type d -prune -or \
 -type f -name \*.gz -mtime ${RETAIN} -exec rm {} \;
  
  Thank you very much, Otto.  That works just fine.  It's greatly
  appreciated!
 
 Well, even if it helped, I can't reproduce your problem:

 
 find /home/kili -maxdepth 1 -type f -name \* -mtime +1 -exec echo {} \; |
 grep ssh
 
 yields no output at all. [And of course, I *do* have a .ssh directory.]

That's because you are not doing the same search.  Especially
-maxdepth 1 will influence the results. 

-Otto



Re: Semi-OT: Problems getting find to not recurse

2005-07-06 Thread Steffen Kluge
On Wed, 2005-07-06 at 22:19 +0200, Matthias Kilian wrote:
 find /home/kili -maxdepth 1 -type f -name \* -mtime +1 -exec echo {} \; |
 grep ssh

This test is irrelevant to the OP's problem.

 yields no output at all. [And of course, I *do* have a .ssh directory.]

But do you have *files* (-type f) that have ssh in their name and
don't start with a dot (-name \*)?

If you drop both the type -f and -name \* predicates your .ssh
directory will show up just fine.

However, -maxdepth 1 will keep find from recursing into that
directory:

$ touch .ssh/file
$ find . -name file
./.ssh/file
$ find . -maxdepth 1 -name file
$

(OpenBSD 3.7 (GENERIC) #50: Sun Mar 20 00:01:57 MST 2005
[EMAIL PROTECTED]:/usr/src/sys/arch/i386/compile/GENERIC)

Cheers
Steffen.