This article will describe how to use the chmod command to modify file permission in Linux systems.
What is chmod?
The chmod (short for change mode) is a command which allows you to modify file permissions on Linux/ Unix systems.
How to use chmod?
There are three basic file permissions in Linux systems –
- Read (r)
- Write (w)
- Execute (x)
And you can assign all three permissions with the below classes –
- User (u)
- Group (g)
- Other (o)
The user is an account that owns the file. The group which owns the file may also have other accounts as members.
The other is the rest of the accounts in the system.
To view the current file permission in the file, you can use the following command –
ls - la
Here is an example output of File 1, which has read and write permission for the user and only read permission to everyone else on the system.
File 2 has read, write, and execute permission for everyone. In contrast, File 3 has read, write, and execute permission for the only user.
$ ls -la
-rw-r--r-- 1 user group 273 Mar 24 11:28 file1
-rwxrwxrwx 1 user group 1449 Jan 29 14:01 file2
-rwx------ 1 user group 4119 Jan 26 13:22 file3
Following is a syntax to use the chmod command.
chmod [references][operator][modes] filename
Operator: It is to determine whether to add (+), remove (-), or set (=) in the permission
Modes: It is read (r), write (w), and execute (x).
Following is an example to add the execute permission for the user to File 1.
chmod u+x file1
To remove the write permission for others for File 2:
chmod o-w file2
For more information on changing file permissions, please use the below command –