The way to find your how-to

View my LinkedIn profile

How to recursively change permissions for files or directories only under Linux OS

Well, to recursively change permissions for all files and folders within the directory given is pretty simple as there is -R flag/switch for chmod command which goes recursively to each folder and set them up.

chmod -R 755 ./

What to do if we want to change folders or files only?
It's not that hard like it looks like. The find command seems to be helpful.

Run the command below to change folders only (where '.' is the current directory):

find . -type d -exec chmod 755 {} \;

or this one for files only:

find . -type f -exec chmod 644 {} \;

Last modified on:

Comments

Ernesto
30 Jul 2012, 07:54
This was extremely helpful for me too, so thanks for the tip. Exactly what I was looking for.

Now, if you could explain the syntax a little bit in order for us to be able to invent similar constructs? I am trying to understand exactly everything after the 644, that is

{} \;

What does this stand for?
Joel
31 Jul 2012, 04:04
Ernesto:

It's all in 'man find'.
The {} gets replaced by the current file 'find' is processing (which is why you don't need to use 'chmod -R'), and \; is just there to mark the end of the exec expression.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 
 
Powered by Scriptsmill Comments Script