Re: find and NFS mounts
- From: Kees Theunissen <theuniss@xxxxxxxx>
- Date: Sun, 28 Oct 2007 03:49:12 +0100
barcaroller wrote:
Can anyone tell me why the following 'find' command still descends into NFS-mounted directories:
prompt> find . -iname '*' -fstype ext3 -print
You want to know why. I'll try to explain that in a few words.
I'm afraid that this needs to be be a little technical. :-)
Let's have a look at a few lines of the find(1) manpage.
This is taken from the find(1) manpage on a Slackware 11.0 system.
NAME
find - search for files in a directory hierarchy
SYNOPSIS
find [-H] [-L] [-P] [path...] [expression]
DESCRIPTION
This manual page documents the GNU version of find. GNU find searches
the directory tree rooted at each given file name by evaluating the
given expression from left to right, according to the rules of prece-
dence (see section OPERATORS), until the outcome is known (the left
hand side is false for and operations, true for or), at which point
find moves on to the next file name.
[ snip ]
True; print the full file name on the standard output, followed
by a newline.
[ snip ]
expr1 expr2
Two expressions in a row are taken to be joined with an implied
"and"; expr2 is not evaluated if expr1 is false.
expr1 -a expr2
Same as expr1 expr2.
expr1 -and expr2
Same as expr1 expr2, but not POSIX compliant.
expr1 -o expr2
Or; expr2 is not evaluated if expr1 is true.
expr1 -or expr2
Same as expr1 -o expr2, but not POSIX compliant.
What this says is that -in your case- find will traverse the directory
tree rooted at "." and for each directory entry in this tree the
expression -with the implicit "and's" inserted-
(-iname '*') -and (-fstype ext3) -and (-print)
will be evaluated.
The first thing you should note is that the first term of the expression
(-iname '*') will always evaluate to "true". So this is just a waste of
CPU cycles without any effect on the generated output.
If the second term of the expression (-fstype ext3) is false then
the only effect will be that the third term (-print) will not be
evaluated. This does *not* mean that the rest of the directory
will be skipped. For that effect you should use "-prune".
From the manpage:
-prune
If -depth is not given, true; if the file is a directory, do not
descend into it.
If -depth is given, false; no effect.
I think that the following command will do what you want:
find . -fstype ext3 -print -o -prune
Just for completeness: if you have a really weird configuration with
ext3 file systems mounted somewhere in an nfs tree, then you should not
use this "-o -prune" construction.
Regards,
Kees.
--
Kees Theunissen.
.
- References:
- find and NFS mounts
- From: barcaroller
- find and NFS mounts
- Prev by Date: Re: Non-existing environment variable
- Next by Date: Re: A bug in Etch's log rotate?
- Previous by thread: find and NFS mounts
- Next by thread: Non-existing environment variable
- Index(es):
Relevant Pages
|