How to Check and Change File Permission

In this blog we will discuss how to quickly check the file permission via command line and then change file permission.

How to Check File Permission

To check file permissions, you can use the ls command with the -l option in the terminal. Here’s how you can do it.

Open the terminal and Navigate to the directory where the file is located using the cd command. Once you are in the required directory, run the bash command ls -l to list the files and their permissions. This command will display a detailed listing of the files in the current directory, including their permissions.

Locate the file you are interested in within the listing. The file permissions will be displayed as a combination of letters and symbols, such as -rw-r--r--.

  • The first character represents the file type. For example, - indicates a regular file, d indicates a directory.
  • The subsequent characters are divided into groups of three, representing the file’s permissions for the owner, group, and other users, respectively.
    • The three characters in each group represent read (r), write (w), and execute (x) permissions, respectively.
    • If a permission is granted, the corresponding letter will be displayed. If it is denied, a hyphen (-) will be shown.
  1. The permissions can be interpreted as follows:
    • r (read): Allows the file to be read and viewed.
    • w (write): Allows the file to be modified or overwritten.
    • x (execute): Allows the file to be executed as a program or script.
    • - (hyphen): Indicates that the permission is not granted.
  2. By checking the file permissions, you can determine which actions are allowed or restricted for the file’s owner, group, and other users.

How to Change File Permission

To change file permission, you can use the chmod command in the terminal. Here’s how you can do it:

Open the terminal on your system using run as administrator. Navigate to the directory where the file is located using the cd command. Once you are in the appropriate directory, run the following command to change the file permissions:

  • chmod permissions filename
  • Replace “permissions” with the desired permission settings and “filename” with the name of the file you want to modify.The “permissions” can be specified in different ways:
    • Numeric Method: You can use a numeric value to represent the permission settings. Each permission is assigned a number: read (4), write (2), and execute (1). The sum of these numbers represents the permission combination. For example:
      • chmod 644 filename sets read and write permissions for the owner and read-only permissions for the group and others.
      • chmod 755 filename sets read, write, and execute permissions for the owner, and read and execute permissions for the group and others.
    • Symbolic Method: You can use symbolic notations to specify the permission settings. The symbols include:
      • u for the owner, g for the group, o for others, and a for all users.
      • + to add a permission, - to remove a permission, and = to set permissions explicitly.
      • r for read, w for write, and x for execute permissions.
      For example:
      • chmod u=rw,go=r filename sets read and write permissions for the owner and read-only permissions for the group and others.
      • chmod a+x filename adds execute permission for all users.
  • After executing the chmod command, the file permissions will be updated accordingly.

Please note that changing file permissions may require appropriate permissions or administrative privileges. If commands don’t work directly try to run it with administrative privileges. You can place sudo before the commands(eg: sudo chmod u=rw,go=r filename ) . Be cautious when modifying permissions, as incorrect settings can impact the security and functionality of the file or system.

Don't Miss Out! Subscribe to Read Our Latest Blogs.

If you found this blog helpful, share it on social media.

Subscription form (#5)

Leave a Comment

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Scroll to Top