The chmod command in Linux is used to change the file permissions of a file or directory. The name stands for "change mode," and it allows users to specify who can read, write, or execute a file.
Syntax
The basic syntax of the chmod command is:
chmod [options] mode file
Modes
Permissions can be set using two notations:
-
Symbolic Notation: Uses letters to represent permissions.
r: Readw: Writex: Executeu: User (owner)g: Groupo: Othersa: All (user, group, and others)
Example:
chmod u+x file.txt # Adds execute permission for the owner chmod go-w file.txt # Removes write permission for group and others -
Octal Notation: Uses numbers to represent permissions.
4: Read2: Write1: Execute
The permissions are combined by adding the values. For example,
7(4+2+1) gives read, write, and execute permissions.Example:
chmod 755 file.txt # Sets read, write, execute for owner; read and execute for group and others
Usage
The chmod command is essential for managing file security and access control in a Linux environment, allowing users to specify who can perform actions on files and directories.
