The chmod command has several options for changing file permissions. Here are some commonly used options:
-
Add Permissions:
+r: Add read permission.+w: Add write permission.+x: Add execute permission.
Example:
chmod +r file.txt # Adds read permission to file.txt -
Remove Permissions:
-r: Remove read permission.-w: Remove write permission.-x: Remove execute permission.
Example:
chmod -x script.sh # Removes execute permission from script.sh -
Set Exact Permissions:
You can set permissions explicitly using numeric values:0: No permission1: Execute2: Write4: Read
You can combine these values for user, group, and others. For example:
chmod 755 file.txt: Sets read, write, and execute for the owner, and read and execute for group and others.chmod 644 file.txt: Sets read and write for the owner, and read for group and others.
-
Recursive Change:
Use the-Roption to change permissions recursively for directories and their contents.chmod -R 755 directory_name # Changes permissions for all files and subdirectories -
Symbolic Mode:
You can specify permissions using symbolic notation:u: User (owner)g: Groupo: Othersa: All (user, group, and others)
Example:
chmod u+x file.txt # Adds execute permission for the user chmod go-w file.txt # Removes write permission for group and others
These options allow you to customize file permissions according to your needs.
