File and Directory Permissions

File and Directory Permissions

In Linux, permissions determine what actions users and groups can take on files and directories. There are three types of permissions: read, write, and execute. These permissions can be set for three different entities: the file or directory owner, the group owner, and everyone else.


Understanding Permission Notation

To display file and directory permissions in Linux, you can use the ls command with the -l option. This will show you a long listing that includes the permissions, among other information. Here's an example:

$ ls -l -rw-r--r-- 1 user staff 1323 Jan 7 15:35 file.txt drwxr-xr-x 3 user staff 102 Dec 10 14:42 directory/ 


The first column in this output represents the permissions for the file or directory. The first character indicates whether it is a file (-) or a directory (d). The next nine characters are divided into groups of three, with each group representing the permissions for the file or directory owner, the group owner, and everyone else.

Each group of three characters represents read (r), write (w), and execute (x) permissions, in that order. If a permission is not granted, a hyphen (-) is used instead of the corresponding letter.

For example, in the output above, the file file.txt has the following permissions:

  • -rw-r--r--: The first - indicates that this is a file. The owner (user) has read and write (rw-) permissions, while the group owner (staff) and everyone else have only read (r--) permissions.

Similarly, the directory directory/ has the following permissions:

  • drwxr-xr-x: The d indicates that this is a directory. The owner (user) has read, write, and execute (rwx) permissions, while the group owner (staff) and everyone else have read and execute (r-x) permissions.


Changing Permissions with chmod

You can change permissions using the chmod command. Here's the basic syntax:

chmod [permissions] [file/directory] 

The permissions argument can be specified using either numeric notation or symbolic notation.


Numeric Notation

In numeric notation, permissions are represented by a three-digit number. Each digit represents the permissions for one of the three entities in the following order: owner, group, and others. The digits are calculated by adding up the values for each permission type:

  • Read: 4
  • Write: 2
  • Execute: 1

For example, read and write permissions would be represented by 4+2=6, while read, write, and execute permissions would be represented by 4+2+1=7.

To set permissions using numeric notation, you can use a command like this:

chmod 644 file.txt 

This would set the file file.txt to have read and write permissions for the owner, and only read permissions for the group owner and everyone else.


Symbolic Notation

In symbolic notation, permissions are represented using letters and symbols. The basic syntax is:

chmod [who][operator][permission] [file/directory] 
  • who: Specifies which entity to modify the permissions for. This can be any combination of u (owner), g (group owner), and o (others).
  • operator: Specifies how to modify the permissions. This can be + (add), - (remove), or = (


Complete and Continue