?
Solved

Changing Permissions Recursively

Posted on 2006-11-20
5
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 35

Accepted Solution

by:
Duncan Roe earned 1200 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 400 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 400 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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