It's convenient to know how to quickly change multiple files' permissions at once. We will walk you through the steps needed to execute this command and explain what each option does.
Let's get started!
Changing file permissions
To change file permissions in Linux, we use the chmod
command. This command stands for "change mode," and it changes the permissions of files and directories.
The syntax is as follows:
chmod OPTIONS PERMISSIONS FILENAME
The OPTIONS argument allows you to specify how the permissions should change. The most common option is -R
, which is "recursive." This option will cause the chmod
command to change the permissions of all files and subdirectories within the specified directory.
Permissions
The PERMISSIONS argument specifies the new permissions to be set on the file or directory. Three types of permissions can be set: owner, group, and world/other.
- owner - creator of the file or directory,
- group - a collection of users who have access to the file or directory.
- world - everyone else.
Permission Values
Each type of permission is set to one of three values: read, write, or execute.
- Read permission permits a user to view the contents of a file,
- write permission allows a user to modify the contents of a file,
- execute permission allows a user to run a program or script.
Learn more about file permission :
https://www.geekbits.io/the-fundamentals-of-linux-file-permissions/
As much as we use the chmod
command to change the permissions of a single file, It is essential to know how to modify the permissions of multiple files and directories.
Recursive change file permissions
We still use the chmod
command to recursively change the permissions of a file or directory. It means that the command will change the permissions of the specified file or directory and all subdirectories and files within it. To use this feature, you need to use the -R
option.
Syntax:
chmod -R PERMISSION DIRECTORY
For example:
Let's say you have a directory called "geekbits," which contains three subdirectories: "one," "two," and "three." Each of these subdirectories contains several files. You want read, write, and execute permissions to the owner of each file and read and execute permissions to everyone else. You would use the following command:
chmod -R u+rwx,g+rx,o+rx geekbits
This command changes the permissions of all files and subdirectories within the "geekbits" directory. The owner of each file will have read, write, and execute permissions, while the group and world will only have read and execute permissions.
You can achieve the same results using the octal notation:
chmod -R 755 geekbits
Learn more about the Octal notation:
https://www.geekbits.io/the-fundamentals-of-linux-file-permissions/
Change File/Directory Ownership
You can use the -R
option with the chown
command to recursively change the ownership of a file or directory.
For example:
Let's say you want to change the ownership of all files and subdirectories within the "geekbits" directory to user "grandmaster." You would use the following command:
chown -R grandmaster geekbits
This command changes the ownership of all files and subdirectories within the "geekbits" directory to user "grandmaster."
Conclusion
Thank you for reading! We hope this article has helped explain how to recursive change file permissions in Linux. If you have any questions or comments about this article, please feel free to leave a comment below.
Thanks again! :)