How to Recursively Change the Permissions of Files and Directories in Ubuntu?

By Hardik Savani May 1, 2024 Category : Ubuntu

To recursively change the permissions of files and directories in Ubuntu, you can use the "chmod" command with the "-R" option, which stands for "recursive". Here is the general syntax:

sudo chmod -R [permissions] [directory]

Where:

  • "sudo" is used to execute the command with administrative privileges.
  • "chmod" is the command to change permissions.
  • "-R" is the option to apply the changes recursively.
  • "[permissions]" represents the new permissions you want to set, using the numeric or symbolic notation (e.g. 755 or u=rwx,g=rx,o=rx).
  • "[directory]" is the directory where you want to apply the changes.

For example, if you want to set the permissions of a directory called "myfolder" and all its subdirectories and files to 755, you can use the following command:

sudo chmod -R 755 /path/to/myfolder

Note: Be careful when using the recursive option, as it can change the permissions of many files and directories at once. Make sure you understand the implications of the permissions you are setting, and use this command with caution.

Sometimes, we need to give recursively change the permissions of specific files and directories in ubuntu OS. you can open terminal and run bellow command, so let's try this way :

Example

sudo find foldername -exec chmod a+rwx {} ";"

Give more specific!

sudo find foldername -type d -exec chmod 755 {} ";"

sudo find foldername -type f -exec chmod 644 {} ";"

I hope it can help you...

Tags :
Shares