Todays quick question

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:

Comments:

Can't you prune against -path ?

Posted by Geoff Arnold on May 26, 2005 at 10:36 AM BST #

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 $;

Posted by Chris Gerhard on May 26, 2005 at 12:12 PM BST #

Oops, sorry, that's from the BSD <code>find</code> in Mac OS X. I forgot that it wasn't in POSIX.

Posted by Geoff Arnold on May 26, 2005 at 12:19 PM BST #

What about:

find /var ! -name mqueue


Greets from the greeks!

Posted by Filippos C. on June 03, 2005 at 09:37 PM BST #

ooops, nevermind, late night posting is not good :)

Posted by Filippos C. on June 03, 2005 at 09:43 PM BST #

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.

Posted by Alan Hargreaves on June 05, 2005 at 06:59 PM BST #

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.

Posted by Chris Gerhard on June 06, 2005 at 02:14 AM BST #

Post a Comment:
Comments are closed for this entry.
About

This is the old blog of Chris Gerhard. It has mostly moved to http://chrisgerhard.wordpress.com

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today