The ls command along with its -l (for long listing) option will show you metadata about your Linux files, including the permissions set on the file.

$ ls -l

drwxr-xr-x. 4 root root    68 Jun 13 20:25 tuned
-rw-r--r--. 1 root root  4017 Feb 24  2022 vimrc

Breakdown of drwxr-xr-x:

Octal Values

Octal values are numbers that represents permissions. Each permission has a numeric value assigned to it.

For example: If a file has the permissions of drwxr-xr-x the octal value would be 755.

Here is a table of values:

Octal Binary* Effect
0 ––– No permissions (access blocked)
1 –-x Executable**
2 -w- Writable
3 -wx Writable, executable
4 r-– Readable (read-only)
5 r-x Readable, executable
6 rw- Readable, writable
7 rwx Readable, writable, executable

Changing Permissions

There is two ways to change file permissions, symbolic mode or octal values

Symbolic mode

Symbolic mode is a procedural way to change permissions. Meaning it performs the instructions you give. To change permissions using symbolic mode, follow the equation below:

Users(u) or Group(g) or Others(o) +- read(r) or write(w) or execute(x)

# Give user and group read write and execute permissions
$ chmod ug+rwx example.txt
# Remove others read permission
$ chmod o-r example2.txt

Octal values

Octal values are a “desired state” of way to change permissions. Meaning the command takes in what state or set of permissions you want for the file, instead of instructions for what to do with the permissions. To change permissions using octal values, use the chmod + octal value.

# Give user group and others read write and execute permissions
$ chmod 777 example.txt
# Only give user read and write permissions
$ chmod 600 example2.txt