Friday May 08, 2009

Stopping find searching remote directories.

Grizzled UNIX users look away now.

The find command is a wonderful thing but there are some uses of it that seem to cause confusion enough that it seems worth documenting them for google. Today's is:

How can I stop find(1) searching remote file systems?

On reading the documentation the “-local” option should be just what you want and it is, but not on it's own. If you just do:

$ find . -local -print

It will indeed only report on files that are on local file systems below the current directory. However it will search the entire directory tree for those local files even if the directory tree is on NFS

To get find to stop searching when it finds a remote file system you need:


$ find . \\( ! -local -prune \\) -o -print

simple.

Wednesday Sep 12, 2007

Don't let find drop into /proc

Today I had the pleasure of looking at a crash dump of a system where ps, prstat et al were hanging. I never got the chance to get to the bottom of it due to meetings. However there was one command that was running on that dump that jumped out as doing lots of harm to the performance of the system for no benefit. The command was “find / .....”. The find had descended into “/proc” where it would have been walking all the directories locking and unlocking processes when what it was looking for was never going to be in /proc. Clive pointed out similar issues from running ps, prstat on performance by walking /proc and supplied the dtrace to show it.

Given that it is so rarely the case that you would want a find starting form “/” to drop into /proc I wonder if it would not be better if either /proc was invisible in the same way as the “.zfs” directories can be invisible in ZFS. I'd be interested in comments on that.

In the mean time if you really want to run find from “/” do this:

find / \\( -fstype proc -prune \\) -o ....


It will not descend into procfs but in all other respects will be the same.

Thursday May 26, 2005

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:

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