Tuesday, August 14, 2012

How do I set a directory's owner, group, and permissions recursively on a *nix machine via the command line?

Execute the following commands via the command line:
sudo chgrp -R _www /Users/user_dir/target_dir
sudo chmod -R ug=rwx /Users/user_dir/target_dir
sudo find /Users/user_dir/target_dir -type d -exec chmod 2770 {} \;
sudo find /Users/user_dir/target_dir -type f -exec chmod ug=rwx {} \;
The first command sets the group to _www recursively.
The second command sets the owner and group permissions to rwx recursively.
The third command makes it so all new directories get created with the correct permissions (i.e. 2770).
The fourth command makes it so all new files get created with the correct permissions (i.e. rwx).

This post is simply a guide. Your values will differ depending on your desired outcome. In your case you may want to set only the group permissions or only the owner permissions (as opposed to both as illustrated in this post). The actual permission values you end up setting may differ too.

No comments:

Post a Comment

About Me

My photo
I code. I figured I should start a blog that keeps track of the many questions and answers that are asked and answered along the way. The name of my blog is "One Q, One A". The name describes the format. When searching for an answer to a problem, I typically have to visit more than one site to get enough information to solve the issue at hand. I always end up on stackoverflow.com, quora.com, random blogs, etc before the answer is obtained. In my blog, each post will consist of one question and one answer. All the noise encountered along the way will be omitted.