The chmod command in Unix-like systems is used to change the file permissions of a file or directory. It stands for "change mode." With chmod, you can specify who can read, write, or execute a file.
Basic Syntax
chmod [options] mode file
Common Options
+: Adds a permission-: Removes a permission=: Sets the permission and overrides existing ones
Modes
Permissions can be set using:
- Symbolic notation:
u: user (owner)g: groupo: othersr: readw: writex: execute
Example:
chmod u+x file.txt # Adds execute permission for the user
- Octal notation:
4: read2: write1: execute
Example:
chmod 755 file.txt # Sets read, write, execute for user; read, execute for group and others
Example Command
To make a script executable:
chmod +x script.sh
This command adds execute permission to the script.sh file.
