How to Recursively Set Permissions for Directories Only
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to Recursively Set Permissions for Directories Only
Hi all,
My problem is as such:
I have a directory that contains files as well as other directories (may be nested).
Currently, the files have permission 400 (r--------),
and the directories have permission 500 (dr-x------).
What i want to do, is to chmod the files and directories such that
the files have permission 644 (rw-r--r--),
and the directories have permission 755 (drwxr-xr-x).
Now, i have easily set the permission of all files AND directories to 644 by doing:
chmod -R u+w *
chmod -R ugoa+r *
The remaining step will be to set the permissions for the directories to 755, while leaving the permissions for the files at 644.
The find command is a real Swiss Army Knife of file management. Here is a command to do what you said was the remaining step, changing the permissions of the directories to 755 while leaving the regular files alone. Just as in the example that you provided I will start with the current working directory at the top of the tree to be changed.
find . -type d -exec chmod 755 {} \;
The find command will see the . and .. directories in your current working directory. The command may change the permission on the current working directory and its parent. Check the permission on the current working directory and its parent after running the command.
Last edited by stress_junkie; 12-29-2005 at 03:45 PM.
Thanks! This is just what i need! Just need to understand something further.
I just read through the man page for find, and understand most of what the command does:
You're looking for all "files" below the current directory, that are of type directories, and executing the command on the found filenames by substituting the "{}" with each filename.
However, i don't understand what the last two characters, the slash and the semi-colon (\; ) are for...
The slash and the semicolon are part of the secret knowledge to keep newbies frustrated.
I'm not 100% sure about the next four statements but here goes. The slash is an escape character telling the bash shell to not interpret the next character. The semicolon designates the end of the find command. It is only necessary in the case where you use the -exec <command> option of the find command. It probably helps the shell parser to figure out where your find command ends.
Last edited by stress_junkie; 12-30-2005 at 09:57 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.