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
30 Jul 2012, 07:54
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?
31 Jul 2012, 04:04
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.