ignoring directories in find

ignoring directories in find

am 17.11.2007 11:08:12 von Mag Gam

Hi All,

I have a very large filesystem, where I would like to skip some ".foo"
directories. This filesystem is about 500GB, and it contains a
directory called ".foo" in many locations, ie

/largefs/a/b/c/.foo/backup/backup
/largefs/.foo/backup/backup
/largefs/a/b/c/d/.foo/

Basically, I want to search thru the filesystem, but ignore .foo and
its subdirectories. I am using something like this now...

find /largefs/ -name "*.foo*" -prune -o -user some_user -ls

But find is still finding '.foo' filesystem. Am I doing something
wrong?

TIA

Re: ignoring directories in find

am 17.11.2007 11:57:06 von Kenan Kalajdzic

magawake wrote:
> Hi All,
>
> I have a very large filesystem, where I would like to skip some ".foo"
> directories. This filesystem is about 500GB, and it contains a
> directory called ".foo" in many locations, ie
>
> /largefs/a/b/c/.foo/backup/backup
> /largefs/.foo/backup/backup
> /largefs/a/b/c/d/.foo/
>
> Basically, I want to search thru the filesystem, but ignore .foo and
> its subdirectories. I am using something like this now...
>
> find /largefs/ -name "*.foo*" -prune -o -user some_user -ls
>
> But find is still finding '.foo' filesystem. Am I doing something
> wrong?

The second expression should exclude the ".foo" directories. Try this:

find /largefs -name .foo -prune -o ! -name .foo -user some_user -ls

--
Kenan Kalajdzic

Re: ignoring directories in find

am 17.11.2007 12:29:14 von Mag Gam

On Nov 17, 2:57 am, Kenan Kalajdzic wrote:
> magawake wrote:
> > Hi All,
>
> > I have a very large filesystem, where I would like to skip some ".foo"
> > directories. This filesystem is about 500GB, and it contains a
> > directory called ".foo" in many locations, ie
>
> > /largefs/a/b/c/.foo/backup/backup
> > /largefs/.foo/backup/backup
> > /largefs/a/b/c/d/.foo/
>
> > Basically, I want to search thru the filesystem, but ignore .foo and
> > its subdirectories. I am using something like this now...
>
> > find /largefs/ -name "*.foo*" -prune -o -user some_user -ls
>
> > But find is still finding '.foo' filesystem. Am I doing something
> > wrong?
>
> The second expression should exclude the ".foo" directories. Try this:
>
> find /largefs -name .foo -prune -o ! -name .foo -user some_user -ls
>
> --
> Kenan Kalajdzic

Thank, I just realized that .foo is only in the first level.

Is it possible to find files, 2nd level and beyond? and just ignore
first level?

TIA

Re: ignoring directories in find

am 17.11.2007 13:16:12 von Maxwell Lol

magawake writes:

> Hi All,
>
> I have a very large filesystem, where I would like to skip some ".foo"
> directories. This filesystem is about 500GB, and it contains a
> directory called ".foo" in many locations, ie
>
> /largefs/a/b/c/.foo/backup/backup
> /largefs/.foo/backup/backup
> /largefs/a/b/c/d/.foo/

you can always do
find | grep -v '\.foo' | ....

Re: ignoring directories in find

am 18.11.2007 14:51:53 von Sven Mascheck

Kenan Kalajdzic wrote:
> magawake wrote:

>> find /largefs/ -name "*.foo*" -prune -o -user some_user -ls
>>
>> But find is still finding '.foo' filesystem.

What find version still prints .foo here?
BTW, ".foo" without pattern matching is sufficient.


> The second expression should exclude the ".foo" directories. Try this:
> find /largefs -name .foo -prune -o ! -name .foo -user some_user -ls

The directories are already matched by the first expression,
so excluding again in the second must not make a difference.

Re: ignoring directories in find

am 18.11.2007 22:27:18 von Kenan Kalajdzic

Sven Mascheck wrote:
> Kenan Kalajdzic wrote:
>> magawake wrote:
>
>>> find /largefs/ -name "*.foo*" -prune -o -user some_user -ls
>>>
>>> But find is still finding '.foo' filesystem.
>
> What find version still prints .foo here?
> BTW, ".foo" without pattern matching is sufficient.
>
>> The second expression should exclude the ".foo" directories.
>> Try this:
>> find /largefs -name .foo -prune -o ! -name .foo \
>> -user some_user -ls
>
> The directories are already matched by the first expression,
> so excluding again in the second must not make a difference.

You are right, thank you. Let me just explain my suggestion.

Quoting from SUSv3:

If no expression is present, -print shall be used as the
expression. Otherwise, if the given expression does not
contain any of the primaries -exec, -ok, or -print, the
given expression shall be effectively replaced by:

( given_expression ) -print

The -ls primary is not specified as "standard", so the above
rule could apply to it, which would turn the following expression

-name .foo -prune -o -user some_user -ls

into

( -name .foo -prune -o -user some_user -ls ) -print

This would print the ".foo" directories, which is what the OP
didn't want. However, since -ls is treated as a special "kind"
of -print, in practical implementations the replacement doesn't
take place.

--
Kenan Kalajdzic