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
Solved

Changing Permissions Recursively

Posted on 2006-11-20
5
237 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

829 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