1833389 Members
2905 Online
110052 Solutions
New Discussion

Re: find

 
SOLVED
Go to solution
navin
Super Advisor

find

Hello i have to find out a files and directories that are owned by user"x" and change the ownership to user "y" . But i have to skip the directory .snapshot and automount direcotory .But it did not skip those directories .What is wrong.pls help.tahnks
i have used the below command
find / -user -prune -name .snapshot,amd_mnt -o -print -exec chown {} \;
Learning ...
5 REPLIES 5
Ivan Ferreira
Honored Contributor
Solution

Re: find

I would run something like this:


find / ! -name .snapshot ! -name amd_mnt -user olduser -exec chown {} \;
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
James R. Ferguson
Acclaimed Contributor

Re: find

Hi Navin:

I prefer adding negated '-path' as:

# find / -user -path "/snapshot*" -a ! -path "/amd_mnt/*" -exec chown {} \+

Note that on 11.0 and later, the use of the '+' terminator improves performance by bundling multiple arguments to the object of the '-exec' much like 'xargs' would do.

Regards!

...JRF...




Sandman!
Honored Contributor

Re: find

As noted by JRF it is better to use "-path" instead of "-prune" which chops off everything below that directory. Try the find(1) command below:

find / -user ! \( -path "/.snapshot" -o "/amd_mnt" -type d \) -a \
\( -path "/.snapshot/*" -o -path "/amd_mnt/*" -type f \) |
xargs -n1 chown
Dennis Handly
Acclaimed Contributor

Re: find

>Sandman: Try the find(1) command below:

You have operator precedence issues with your command. -a has higher percedence than -o, so you need extra \( \). And you should use -exec {} +

I'm not sure why you have that second check for file versions of those two paths?
Was that "\" a "!"?
If so, you probably want an extra "*" before
/.snapshot/*. Since I believe there are lots of those directories, at every level.

find / -user ! \( \( -path "/.snapshot" -o "/amd_mnt" \) -type d \) -a
! \( \( -path "/.snapshot/*" -o -path "/amd_mnt/*" \) -type f \) -exec chown {} \+
Sandman!
Honored Contributor

Re: find

>Dennis

Glad you noticed the find(1) I posted as it frankly does not make much sense. Moreover the catchall {} + operator is more efficient over pipelining it to xargs(1). Guess that what happens when postings are untested :( and so here is the tested version of the find(1) posted earlier and hope it helps :)

find / -user \
! \( -path "/.snapshot" -o \
-path "/.snapshot/*" -o \
-path "/amd_mnt" -o \
-path "/amd_mnt/*" \) \
-exec chown {} +