[CentOS] Find and excluding directory

Robert Nichols rnicholsNOSPAM at comcast.net
Tue Feb 2 14:56:14 UTC 2010


Tom Brown wrote:
> Hi
> 
> I have to use find to change the perms of a directory and files within 
> that directory recursively but i need to exclude a directory within the 
> top level directory, as its a netapp and so contains a read only 
> .snapshot dir.
> 
> I have tried...
> 
> # find /var/data/foo -path '\.\/\.snapshot' -prune -o -exec chown 
> usera:groupb {} \;
> 
> but
> 
> chown: changing ownership of `/var/data/foo/.snapshot': Read-only file 
> system
> chown: changing ownership of `/var/data/foo/.snapshot/hourly.0': 
> Read-only file system
> chown: changing ownership of 
> `/var/data/foo/.snapshot/hourly.0/filename': Read-only file system

Your "-path" argument is wrong.  Try this:

     find /var/data/foo -path '/var/data/foo/.snapshot' -prune -o -exec chown 
usera:groupb {} +

You need the whole path, and there is no need to escape the '.' character.
I've also used "+" as the terminator.  That's just an efficiency issue.  It
makes 'find' build command lines with as many matches as will fit rather
than invoking 'chown' separately for each one.

-- 
Bob Nichols     "NOSPAM" is really part of my email address.
                 Do NOT delete it.



More information about the CentOS mailing list