Skip to content

Todays quick question

May 26, 2005

When running find down a single file system how can you exclude a particular directory?

For example you wish to search /var but do not want to search /var/spool/mqueue. The problem here is that if you do the obvious:

find /var \( -name mqueue -prune \) -mount -print

the find will stop on any file called “mqueue” and not just /var/spool/mqueue.

The solution is to use the -inum option to find:


find /var \( -inum $(ls -di /var/spool/mqueue | nawk ‘{ print $1 }’ ) -prune \) -mount -print

There must be a better way, so let me know what is is.

Tag:

Advertisements

From → Solaris

8 Comments
  1. Can’t you prune against -path ?

  2. I’m not sure I understand you Geoff. There is no -path option to find (though it would be nice for this).

    
    : enoexec.eu FSS 47 $; find /var/tmp \( -path /var/tmp/spam -prune \) -o -pri>
    find: bad option -path
    find: [-H | -L] path-list predicate-list
    : enoexec.eu FSS 48 $;
    
  3. Oops, sorry, that’s from the BSD <code>find</code> in Mac OS X. I forgot that it wasn’t in POSIX.

  4. Filippos C. permalink

    What about:
    find /var ! -name mqueue

    Greets from the greeks!

  5. Filippos C. permalink

    What about:
    find /var ! -name mqueue

    Greets from the greeks!

  6. Filippos C. permalink

    ooops, nevermind, late night posting is not good 🙂

  7. Of course if you are only goingto be piping the output to something else, egrep is your friend.

    find /var -print | egrep -v '^/var/spool/mqueue/
    

    Unixphilosphy: Small tools with small functionality, strung together to make big tools.
    Alan.

  8. The egrep option is o.k. but only if the directory you wish to not search is small.
    If it contains many millions on objects then you still suffer the performance penalty of accessing all those entries.Perhaps when OpenSolaris goes live someone will add a -path option to find.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: