Ubuntu: how to have chown only effect folders, not files?


I have to chmod a structure of subfolders which contain more sufolders and also files naturally.

Now I need to change access rights (owner:group, no acl at this point) to this complete structure in the same manner. Only I want 775 for folders but 664 for files. How can I achieve that? man chown does not seem to give a solution, so I thought a pipe of find and chown could do it. My knowledge of pipes is pretty basic. I think you give a command and sent the output of that command through the second command.

find -type d | chmod -R 775 *  

is my guess but does not respect the output of my find command. Probably the '*' in the chown command overrules the output of find somewhat

any ideas how to tweak this in my favor?


Don't use the -R flag with chmod, which makes it recursive (applicable to all folders and files contained in the arguments). Use:

find . -type d -exec chmod 775 {} +  


Update: I misread, see @muru's don't use -R This might work:

chmod 775 $(find -type d)  

It is called command substitution

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »