SUMMARY: "find" syntax question

From: Christopher L. Barnard (
Date: Wed Dec 04 1996 - 15:56:10 CST

I asked:

> I'm trying to get the syntax right on this "find" command, and I'm
> hoping that someone else can see what I'm missing. I want this
> command to only look on local filesystems and ignore anything that
> is NFS mounted. "-mount" or "-xdev" don't work, because I want it
> to look on all of the local filesystems, not just /. "-local" doesn't
> seem to work properly, because this line
> /usr/bin/find / -local -name core -mtime +2 -print
> still generates lots of error messages about unreadable directories from
> NFS mounted directories that are not world readable. I don't see anything
> else in the man page that looks like what I want... Is there a way to
> do this without writing a script that parses the /etc/vfstab file for
> each local filesystem and then calls find individually with the -mount flag
> for each of these filesystems?

The suggestions:

Well, I got 25 responses, three of which worked. Suggestions included adding
these additional instructions to the find command:

-prune /net This unfortunately won't work because most of the filesystems
                that I wanted to prune are mounted from the
                automounter map, so they don't show up in /net, or /stage,
                or /home, or anything nice and easy like that.

-mount instead of -local This doesn't work because it would only search
  or the filesystem in which it was started- in this
  -xdev for SunOS case /. I want it to search all local filesystems.

-fstype ufs This doesn't work because it will still try to look at
   or all of the files (to decide if they are on a ufs filesystem
  -fstype 4.2 or not) and what I'm trying to get rid of are the warnings
  for SunOS when it finds NFS-mounted non-world-readable files. This
                flag did not change that.

-fstype nfs -prune I had high hopes for this option. However, it still
                    didn't work; for some reason I do not understand, find
                    was able to determine that the auto_direct-mounted
                    filesystems were of type nfs, but it reported that
                    all of its subdirectories were of type ufs. This left
                    me back in the same point as "-fstype ufs", above.

use GNU find instead. Nope, didn't work. GNU find has the same problems.

and The Solution:

What this ends up requiring is a script, not just a single call to find.
The script reads through /etc/mnttab or /etc/vfstab looking for local
filesystems, and then calls find individually on each of those filesystems
(with -mount or -xdev to keep the find confined to that filesystem).
The three people who suggested something like this were Tony R McKenzie
<>, Chris Wozniak <>, and Ernst-Gunar
Ortlepp <>. Chris and Ernst-Gunar gave me code fragments,
which I'll include here (summarized) for those who are interested. I went
with Chris' solution, but Ernst-Gunar's also worked for me in a mockup.

# Author: Chris Wozniak
OSREV=`uname -r | cut -f 1 -d.`
# List mounted filesystems
if [ $OSREV -ge 5 ]; then
# on SunOS 5.x
     MNTLIST=`/usr/bin/grep ufs /etc/mnttab | awk '{print $2}'`
# on SunOS 4.x
     MNTLIST=`/bin/grep ' 4.2 ' /etc/mtab | awk '{print $2}'`
# find and delete core files
     find $FSYS -name core -ctime +1 -xdev -exec rm -f {} \;
list=`df | grep /dev/dsk | awk '{print $1}'`
find $list -{what you want to do}

A final note: There appears to be a bit of confusion out there about find
(not that I'm surprised -- I was too). Since some of you may be relying on
a potentially broken find script, I wanted to draw attention to these two

* Adding "-fstype ufs" does *not* stop find from looking at all of the
   files on any NFS mounted filesystems. It won't react to any thing it
   finds out there, but the find script is still taking the time to look
   at everything. On a busy server, this could be adding a significant
   amount of time to the find process.

* Adding "-mount" (or "-xdev" for SunOS) means that it will only look at
   the one filesystem in which the find command was started -- it does *not*
   look at all local filesystems.

Thanks to:

"Nicholas R LeRoy" <>
Richard Snyder <>
"Plesha, Thomas A. (NSLC Pacific)" <>
"Mark `Hex' Hershberger" <> (Dave Haut)
Dan Pritts <> (Dale Wiles)
"Bruce Rossiter" <>
Tim Buller <>
Mark Belanger <> (Bismark Espinoza)
"Kevin P. Inscoe" <>
"David Evans" <>
Jochen Bern <> (Kevin Sheehan {Consulting Poster Child}) (Eric M. Stone)
Chris Wozniak <> (Kris Briscoe)
Tony R McKenzie <> (James Wendling) (Ernst-Gunar Ortlepp)

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:17 CDT