Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to exclude a list of full directory paths in find command on Solaris
    primarykey
    data
    text
    <p>I have a very specific need to find unowned files and directories in Solaris using a script, and need to be able to exclude full directory paths from the find because they contain potentially thousands of unowned files (and it's normal because they are files hosted on other servers). I don't even want find to search in those directories as it will hang the server (cpu spiking to 99% for a long time), therefore piping the find results in egrep to filter out those directories is not an option.</p> <p>I know I can do this to exclude one of more directories by name:</p> <p><code>find / -mount -local \( -type d -a \( -name dir1 -o -name dir2 -o dir3 \) \) -prune -o \( -nouser -o -nogroup \) -print</code></p> <p>However, this will match dir1 and dir2 anywhere in the directory structure of any directories, which is <strong>not</strong> what I want at all.</p> <p>I want to be able to prevent find from even searching in the following directories (as an example):</p> <pre><code>/opt/dir1 /opt/dir2 /var/dir3/dir4 </code></pre> <p>And I still want it to find unowned files and directories in the following directories:</p> <pre><code>/opt/somedir/dir1 /var/dir2 /home/user1/dir1 </code></pre> <p>I have tried using regex in the -name arguments, but since find only matches 'name' against the basename of what it finds, I can't specify a path. Unfortunately, Solaris's find does not support GNU find options such as -wholename or -path, so I'm kind of screwed.</p> <p>My goal would be to have a script with the following syntax:</p> <p><code>script.sh "/path/to/dir1,/path/to/dir2,/path/to/dir3"</code></p> <p>How could I do that using find and standard sh scripting (/bin/sh) on Solaris (5.8 and up)?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COstarting `find` from '/' is problematic. A pre-processing step in your script that grabs just the top level path elements, ie. /opt, /var, and then runs find just for those dirs, after excluding the dirs you're not interested in??? Just an idea, good luck! If you come up with your own solution, please post, as this is an interesting problem. You might also get more eyes on this if you post at http://unix.stackexchange.com/
      singulars
    2. COStarting from / is actually required. The purpose of this script is to produce audit compliance results listing all unowned files and dirs in servers we support for our clients, without knowing where they could be. We know for sure there are some directories we never want to scan (/proc, /dev, remote mounts, etc...), but we always need to scan everything else. We gave lots of thought about using an inclusion list instead of exclusion list, and we had no choice but to go with the exclusion option cause it's the one that covered the most unknown cases (still following me?).
      singulars
    3. COJust duplicated the post on unix.stackexchange.com as suggested: _http://unix.stackexchange.com/questions/23077/how-to-exclude-a-list-of-full-directory-paths-in-find-command-on-solaris_
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload