How to Change File Permissions in Linux from the Terminal

Understanding how to view and change file permissions in Linux is an important skill to have. Your files and your system could potentially be compromised if certain users can access all of your files. This skill allows you to protect your files and prohibit other users from accessing certain files.


Open the Terminal

You will be using the terminal to change file permissions.

Locate your file.

In order to change the permissions of a file, you must be in the directory where the file is located. You can change directories by using the command cd, followed by a space and the name of the directory you want to switch to.

View the current permissions of the file.

You should check the current permissions of the files before changing them. The permissions may not need to be changed. Use the command ls -l . Your output will provide details on each file in the directory.

  • In the image above, the red square is the current file permissions and the blue square is the name of the file.WH.shared.addScrollLoadItem(‘3f6cc9ec489a4c07ef7138f55305ef15’)WH.performance.clearMarks(‘image1_rendered’); WH.performance.mark(‘image1_rendered’);

Understand the permissions of the file.

The file permission string is broken up into blocks. The entities that are files will always begin their permission string with “-“. This is shown in the green square. The rest of the permission string (after the “-“) represents:

  • Permissions for the owner (e.g., the first three characters (“rw-“) in the red square)
  • Permissions for the group owner (e.g., the second three characters (“r–“) in the yellow square)
  • Permissions for others (e.g., the last three characters (“r–“) in the blue square)

Find the octal number that matches the permissions you want.

Use the chart to find the octal number of the permissions you want the file to have. This octal number will be used in changing file permissions.

Use the “chmod” command to change the file’s permissions.

Use chmod followed by the octal number and the file name. In this case, we are changing the permissions of the file “f5”. This command will change your file’s permissions to the permissions that correspond with the octal number.

Verify that the file’s permissions have been changed.

After using the “chmod” command, it is important to make sure the file now has the permissions you want. To view the current file permissions, use the command ls -l. If the permissions of the file have changed to what you want, you have successfully changed your file’s permissions.

Leave a Comment