How to change the permissions of a file or directory in Linux?

In Linux, you can use the chmod command to change the permissions of a file or directory. The basic syntax of this command is as follows:

chmod [mode] [file/directory]

The mode signifies the permission to be modified, which can be represented using numbers or symbols. The permissions represented by numbers are a three-digit number, with each digit representing the permissions of the owner, group, and other users, respectively, as follows:

  1. 4: Read access.
  2. 2: permission to write
  3. 1:executive rights

For instance, to set the permissions of the file test.txt to allow the owner to read and write, the group to read, and others to read, you can use the following command:

chmod 644 test.txt

In addition to using numbers to represent permissions, changes in permissions can also be shown using symbols. Common symbols include:

  1. Increase access rights.
  2. – Reduce the level of permissions
  3. =:Establishing permissions

For example, to set the permissions of the file test.txt as readable, writable, and executable for the owner, readable and executable for the group, and not writable or executable for other users, you can use the following command:

chmod u=rwx,g=rx,o-rwx test.txt

In practical use, choose the appropriate permission representation to change the permissions of a file or directory as needed.

广告
Closing in 10 seconds
bannerAds