
Chmod Command in Linux File Permissions
In Linux, access to the files is managed through the file permissions, attributes, and ownership. This ensures that only authorized users and processes can access files and directories.
This tutorial covers how to use the chmod
command to change the access permissions of files and directories.
Linux File Permissions
Before going further, let’s explain the basic Linux permissions model.
In Linux, each file is associated with an owner and a group and assigned with permission access rights for three different classes of users:
- The file owner.
- The group members.
- Others (everybody else).
File ownership can be changed using the chown
and chgrp
commands.
There are three file permissions types that apply to each class:
- The read permission.
- The write permission.
- The execute permission.
This concept allows you to specify which users are allowed to read the file, write to the file, or execute the file.
File permissions can be viewed using the ls
command:
ls -l filename.txt
-rw-r--r-- 12 linuxize users 12.0K Apr 8 20:51 filename.txt
|[-][-][-]- [------] [---]
| | | | | | |
| | | | | | +-----------> 7. Group
| | | | | +-------------------> 6. Owner
| | | | +--------------------------> 5. Alternate Access Method
| | | +----------------------------> 4. Others Permissions
| | +-------------------------------> 3. Group Permissions
| +----------------------------------> 2. Owner Permissions
+------------------------------------> 1. File Type
The first character shows the file type. It can be a regular file (-
), directory (d
), a symbolic link (l
), or any other special type of file.
The next nine characters represent the file permissions, three triplets of three characters each. The first triplet shows the owner permissions, the second one group permissions, and the last triplet shows everybody else permissions. The permissions can have a different meaning depending on the file type.
In the example above (rw-r--r--
) means that the file owner has read and write permissions (rw-
), the group and others have only read permissions (r--
).
Each of the three permission triplets can be constructed of the following characters and have a different effects, depending on whether they are set to a file or to a directory:
Effect of Permissions on Files
Effect of Permissions on Directories (Folders)
In Linux, Directories are special types of files that contain other files and directories.
Using chmod
The general form of the chmod
command take the following form:
Linux File Permissions, Linux File Permissions All Users, Linux File Permissions Command, Linux File Permissions Examples
Chmod Codes, Chmod In Linux