Changing Permissions Recursively

Posted on 2006-11-20
Last Modified: 2010-04-20

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?


Question by:hankknight
LVL 16

Author Comment

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"
LVL 34

Accepted Solution

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.
LVL 16

Author Comment

ID: 17982794

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

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

Assisted Solution

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


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


Assisted Solution

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.

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

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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…
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.

816 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

10 Experts available now in Live!

Get 1:1 Help Now