LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   stupid question about chmod (https://www.linuxquestions.org/questions/linux-general-1/stupid-question-about-chmod-224225/)

salami 08-30-2004 04:51 AM

stupid question about chmod
 
hi there

i need to set the file permissions on a directory and all subdiretories and files. files should have 660 and directories 770. now here's the problem... how can i tell chmod to only apply it to directories/files recursively?

thanks a lot!

Charalambos 08-30-2004 04:57 AM

Re: stupid question about chmod
 
Quote:

Originally posted by salami
how can i tell chmod to only apply it to directories/files recursively?
Only recursively?
Do you want it to apply recursively (to all subdirectories and files of a directory) or to only one specific directory?
Recursively:
chmod -R 660 directory (The -R option means recursively)
To apply it to only one directory (without the subdirectories affected) apply the above without the option -R.

Dark_Helmet 08-30-2004 05:23 AM

Another way to go about it...

Since you've got two types of permissions, you're probably better off doing it in two commands. It's possible to do it all in one, but unnecessarily difficult (in my opinion). Anyway, find is your friend:
Code:

find /path/to/top/directory -type f -exec chmod 660 {} \;
find /path/to/top/directory -type d -exec chmod 770 {} \;

First command locates only regular files (-type f) located in the top-level directory and subdirectories. For each file found, the chmod command gets executed. The curly braces ( {} ) get replaced with the matching filename when executed. The \; signals where the end of the command is (for the -exec option).

Similarly, the second command finds only directories. It will match the directory given on the commandline and all its subdirectories. It will also perform a similar chmod but with a different set of permissions (770 as opposed to the 660 for files).

Charalambos 08-30-2004 05:27 AM

Quote:

Originally posted by salami
files should have 660 and directories 770.
Sorry, somehow missed that one. :D
Forget my post above, it won't get you the desired result.
Consider Dark_Helmet's solution (he's the guru here anyway...)

salami 08-30-2004 06:25 AM

hi

thanks for your replies!

the way Dark_Helmet described worked perfectly - thanks for the detailed explanation (this will get handy in the future too).


All times are GMT -5. The time now is 07:45 PM.