1748274 Members
4201 Online
108761 Solutions
New Discussion юеВ

Re: Find and Replace

 
SOLVED
Go to solution
rhansen
Frequent Advisor

Find and Replace

Hello,

I have hundreds of files that I need to change the ownerships for. The files are under directory
-rw-rw---- 1 4707 arbor 570 Oct 29 20:03 /opt/hyperion/parmfiles/arbor/ECSDM_INCFC_CCHD_CRNCY_CONV_RATE

I need to change the files owned by UID 4707 to arbor. I was thinking of using for loop.

Any help would be appreciated.

Thanks.
4 REPLIES 4
Patrick Wallek
Honored Contributor
Solution

Re: Find and Replace

Let find do the work:

cd /dir/files/are/in
find . -type f -user 4707 -exec chown arbor {} \+
Suraj K Sankari
Honored Contributor

Re: Find and Replace

Hi,
2 steps required
1st
#cd /opt/hyperion/parmfiles/arbor/ECSDM_INCFC_CCHD_CRNCY_CONV_RATE

2nd
#find . -type f -user 4707 -exec chown arbor {} \;

Suraj
James R. Ferguson
Acclaimed Contributor

Re: Find and Replace

Hi:

Patrick's use of the "+" terminator with the '-exec' command makes things much more efficient than if the '\;' terminator is used.

That is:

# find . -type f -user 4707 -exec chown arbor {} \+

...runs much faster than:

# find . -type f -user 4707 -exec chown arbor {} \;

The '+' syntax causes multiple arguments to be assembled and passed to one instantiation of the 'exec'ed command eliminating the overhead of spawning one process per file.

Lastly, too, you do not need to escape the '+' character and can write:

# find . -type f -user 4707 -exec chown arbor {} +

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: Find and Replace

>>Lastly, too, you do not need to escape the '+' character

True. Old habits die hard though.