7 Examples of command "chmod" On Linux and Explanation
7 Examples of command "chmod" On Linux and Explanation - On Linux or Unix operating systems as there are rules for every file that defines who can access the file and how the file can be located. This rule is called permissions or also commonly known as Permission. To use it, the command used is "chmod" which stands for change mode is used to determine how the files can be accessed.
In general, to run the chmod command syntax is like below
chmod permissions filename options
Permissions can be defined as, for the owner (user), for the group, for others. There are two ways to identify licensing, with symbols (alphanumeric characters), or also by an octal number (0 to 7).
- User (u) can be read (r) and write (w).
- Group (g) can be read.
- Other (o) can be read.
Three File Permissions:
- Read: allowed to read the file contents.
- Write: allowed to write to the archive.
- Execute: allowed to run a file as a program/script.
Three Directory Permission:
- Read: allowed to read the contents of the directory (see the files and subdirectories in that directory).
- Write: permitted to write to the directory. (Makefiles and sub-directories in that directory)
- Execute: allowed to go into that directory.
The numerical value:
- Read: 4
- Write: 2
- Execute: 1
In symbols:
- Read: r
- Write: w
- Execute: x
Adding Licensing Single File / Directory
Change the permissions to set. Symbol + means giving permission. For instance, the example below provides execute permissions for the user.
$ Chmod u + x filename
Adding Dual Licensing For Files / Directories
Just as before, we can give permission for a binary file directory. Examples of his command as below.
$ Chmod u + r, g + w filename
Removing Permissions From the Files / Directories
Examples remove read and write permissions for the user.
$ Chmod u-rx filename
Changing Licensing For All Users In the Files / Directories
The meaning all users are the user, group, and others.
$ Chmod a + x filename
Make licensing A File of the Same With Other Files
$ Chmod -reference = file file2
Applying Permissions For All Files Under Directories
Using the -R option to change permissions recursively as below:
$ Chmod -R 755 directory-name /
Changing Directory Permissions Execute Only On (Not File)
In a directory, there are often several subdirectories and archives. So, this command only to subdirectories only.
$ Chmod u + x
Leave a Comment