How to exclude multiple directories from "Find"

How to exclude multiple directories from "Find"

Post by Jame » Sat, 24 Jun 2006 00:22:39



Hi all,

I am using ksh on AIX 5.2, "Find" does not support "-path"

I searched previous posts and got some hints,
If I want to exclude only /tmp, the following command is working well
find /!(tmp) -user foobar -print

How about to exclude /tmp, /proc, and /dev all together?
Is there a similiar way to do it?

Many thanks,

James

 
 
 

How to exclude multiple directories from "Find"

Post by Jon LaBadi » Sat, 24 Jun 2006 01:04:14



> Hi all,

> I am using ksh on AIX 5.2, "Find" does not support "-path"

> I searched previous posts and got some hints,
> If I want to exclude only /tmp, the following command is working well
> find /!(tmp) -user foobar -print

> How about to exclude /tmp, /proc, and /dev all together?
> Is there a similiar way to do it?

Looks like your shell is handling extended form of glob'ing.

Try find /!(tmp|proc|dev) -user foobar -print

 
 
 

How to exclude multiple directories from "Find"

Post by Bill Marcu » Sat, 24 Jun 2006 01:35:25


On 22 Jun 2006 08:22:39 -0700, James

> Hi all,

> I am using ksh on AIX 5.2, "Find" does not support "-path"

> I searched previous posts and got some hints,
> If I want to exclude only /tmp, the following command is working well
> find /!(tmp) -user foobar -print

> How about to exclude /tmp, /proc, and /dev all together?
> Is there a similiar way to do it?

find /!(tmp|proc|dev)

This works in ksh, or zsh with the KSH_GLOB option.
In other shells, you could pipe the output of find to
grep -v -e '^/proc' -e '^/tmp' -e '^/dev'

--
I never met a piece of chocolate I didn't like.

 
 
 

How to exclude multiple directories from "Find"

Post by Chris F.A. Johnso » Sat, 24 Jun 2006 02:08:15



> On 22 Jun 2006 08:22:39 -0700, James

>> Hi all,

>> I am using ksh on AIX 5.2, "Find" does not support "-path"

>> I searched previous posts and got some hints,
>> If I want to exclude only /tmp, the following command is working well
>> find /!(tmp) -user foobar -print

>> How about to exclude /tmp, /proc, and /dev all together?
>> Is there a similiar way to do it?

> find /!(tmp|proc|dev)

> This works in ksh, or zsh with the KSH_GLOB option.

   And in bash with the extglob option set.

Quote:> In other shells, you could pipe the output of find to
> grep -v -e '^/proc' -e '^/tmp' -e '^/dev'

--
   Chris F.A. Johnson, author              <http://cfaj.freeshell.org>
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   ===== My code in this post, if any, assumes the POSIX locale
   ===== and is released under the GNU General Public Licence
 
 
 

How to exclude multiple directories from "Find"

Post by Stephane Chazela » Sat, 24 Jun 2006 02:13:41



> On 22 Jun 2006 08:22:39 -0700, James

>> Hi all,

>> I am using ksh on AIX 5.2, "Find" does not support "-path"

>> I searched previous posts and got some hints,
>> If I want to exclude only /tmp, the following command is working well
>> find /!(tmp) -user foobar -print

>> How about to exclude /tmp, /proc, and /dev all together?
>> Is there a similiar way to do it?

> find /!(tmp|proc|dev)

> This works in ksh, or zsh with the KSH_GLOB option.
> In other shells, you could pipe the output of find to
> grep -v -e '^/proc' -e '^/tmp' -e '^/dev'

[...]

Alternatively, you can do:

find / \( -name tmp -exec test {} = /tmp \; -o \
          -name proc -a -exec test {} = /proc \; \) -prune -o \
  -user foobar -print
(the two stage test if for speed optimisation).

Which, if you have GNU find can be simplified to:

find / \( -path /tmp -o -path /proc \) -prune -o \
  -user foobar -print

Or you could do:

find /. ! -name . -prune ! -name tmp ! -name proc -exec \
  find {} -user foobar -print

--
Stephane

 
 
 

How to exclude multiple directories from "Find"

Post by Jame » Sat, 24 Jun 2006 02:27:53


Thanks to all of you for such quick and working solutions!

Regards,

James