-   Linux - Software (
-   -   How to Recursively Set Permissions for Directories Only (

edwin11 12-29-2005 02:41 PM

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.

Any suggestion?

TIA and Regards,

mikedeatworld 12-29-2005 02:51 PM

So you want the files to be seen by all users but not excutable by all?

stress_junkie 12-29-2005 03:40 PM

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.

edwin11 12-29-2005 11:29 PM


Originally Posted by stress_junkie
find . -type d -exec chmod 755 {} \;

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... :confused:

Thanks Again,

stress_junkie 12-30-2005 09:54 AM

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.

All times are GMT -5. The time now is 10:56 PM.