• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Changing Permissions Recursively

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
hankknight
Asked:
hankknight
3 Solutions
 
hankknightAuthor Commented:
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
 
Duncan RoeSoftware DeveloperCommented:
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
 
hankknightAuthor Commented:
Thanks!  

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

How do I  determine the numeric user id of "dev"?
0
 
TintinCommented:
grep dev /etc/passwd|cut -f3 -d:

or

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

0
 
dnbCommented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now