Modifying File and Directory Permissions
In Linux, you can modify the permissions of files and directories using the chmod
(change mode) command. There are two main ways to change permissions: using numeric values or symbolic representations.
Using Numeric Permissions
Numeric permissions are represented by a three-digit number, where each digit corresponds to the permissions for the owner, group, and others, respectively. The values for each permission are:
- Read (r): 4
- Write (w): 2
- Execute (x): 1
To set the permissions, you add the values for the desired permissions. For example, 755
would give the owner read, write, and execute permissions, while the group and others have read and execute permissions.
$ chmod 755 example.txt
$ ls -l
-rwxr-xr-x 1 user group 1024 Apr 1 12:34 example.txt
Using Symbolic Permissions
Symbolic permissions use a combination of letters and symbols to represent the permissions. The format is:
[who] [operator] [permissions]
Where "who" can be:
u
: user (owner)
g
: group
o
: others
a
: all (owner, group, and others)
The "operator" can be:
+
: add permission
-
: remove permission
=
: set permission
The "permissions" can be:
r
: read
w
: write
x
: execute
$ chmod u+x,g+r,o+r example.txt
$ ls -l
-rwxr--r-- 1 user group 1024 Apr 1 12:34 example.txt
In the above example, the owner's permissions are set to read, write, and execute, while the group and others have read-only permissions.
By using the chmod
command with either numeric or symbolic permissions, you can easily modify the access rights for files and directories in your Linux system.