In Linux, you can use the chmod
command to change the permissions of a file. The chmod
command stands for “change mode,” and it allows you to modify the permissions of a file or directory.
The basic syntax for the chmod
command is as follows:
chmod [options] mode file
The mode
parameter specifies the new permissions for the file, and the file
parameter specifies the name of the file or directory whose permissions you want to change.
There are two ways to specify the mode
parameter: using symbolic notation or using octal notation.
In symbolic notation, you can specify the permissions as a combination of three components: the owner permissions (u), the group permissions (g), and the other permissions (o). For each component, you can specify three types of permissions: read (r), write (w), and execute (x). You can also use the +
or -
signs to add or remove permissions, or the =
sign to set the permissions to a specific value.
For example, to give the owner of a file read and write permissions, and to give all other users read-only access, you can use the following command:
chmod u=rw,go=r file
In octal notation, you can specify the permissions as a three-digit octal number, where each digit represents the permissions for the owner (first digit), the group (second digit), and others (third digit). Each digit is calculated as the sum of the corresponding permissions, with read permission represented by 4
, write permission represented by 2
, and execute permission represented by 1
.
For example, to give the owner read and write permissions, and to give the group and others read-only access, you can use the following command:
chmod 644 file
This is a basic overview of how to change the permissions of a file in Linux using the chmod
command. There are many other options and advanced usage scenarios for this command, which you can learn more about by reading the chmod
man page or consulting other resources.