Solved

Changing Permissions Recursively

Posted on 2006-11-20
5
234 Views
Last Modified: 2010-04-20
Hello,

I have a directory with dozens of sub-directories and hundreds of files.

Some files have the ownership set to "nobody" and some have the ownership set to "dev".

How can I change ownership for ALL "dev" to "prod", for ALL files and directories, and for both the user and the group?

Thanks.

0
Comment
Question by:hankknight
5 Comments
 
LVL 16

Author Comment

by:hankknight
ID: 17982527
I tried this:

         chown prod /home/mydir/* -R
         chgrp prod  /home/mydir/* -R

But it change ownership of ALL files, even ones that were owned by "nobody".  I ONLY want to change ownership where it was set to "dev"
0
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 300 total points
ID: 17982654
You can use the find command to select the files to change. First of all, determine the numeric user id od "dev". Let's call the result n. Now:

find . -type f -uid n -exec "chown {} newuser \;

will do the job. Type "man find" for an explanation of what the above command line does.
0
 
LVL 16

Author Comment

by:hankknight
ID: 17982794
Thanks!  

   ->> First of all, determine the numeric user id of "dev"

How do I  determine the numeric user id of "dev"?
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 100 total points
ID: 17984455
grep dev /etc/passwd|cut -f3 -d:

or

find . -user dev -exec chown {} prod:group {} \;

0
 
LVL 1

Assisted Solution

by:dnb
dnb earned 100 total points
ID: 17988774
The command "id dev" will tell you the uid of user dev but as Tintin pointed out using find's -user option with the username is easier.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now