In Linux, file permissions can be modified using two modes: symbolic mode and numeric mode. Each mode provides a different way to specify the permissions you want to set for files and directories.
1. Symbolic Mode
Symbolic mode uses letters to represent the user categories and permissions. It allows you to add, remove, or set specific permissions.
-
User Categories:
u: User (owner of the file)g: Group (users who are part of the file's group)o: Others (all other users)a: All (user, group, and others)
-
Operators:
+: Adds a permission-: Removes a permission=: Sets exact permissions (overwrites existing permissions)
-
Permissions:
r: Read permissionw: Write permissionx: Execute permission
-
Examples:
- To add execute permission for the user:
chmod u+x filename.txt - To remove write permission for the group:
chmod g-w filename.txt - To set read and write permissions for the user, and read for group and others:
chmod u=rw,g=r,o=r filename.txt
- To add execute permission for the user:
2. Numeric Mode
Numeric mode uses a three-digit number to represent permissions. Each digit corresponds to the permissions for user, group, and others, respectively.
-
Permission Values:
- Read (
r) = 4 - Write (
w) = 2 - Execute (
x) = 1
- Read (
-
Calculating Permissions:
- You can combine these values by adding them together to set the desired permissions.
- For example:
- Read and write = 4 + 2 = 6
- Read and execute = 4 + 1 = 5
- Read, write, and execute = 4 + 2 + 1 = 7
-
Examples:
- To set permissions to read, write, and execute for the user, and read and execute for group and others:
chmod 755 filename.txt - To set permissions to read and write for the user, and read for group and others:
chmod 644 filename.txt
- To set permissions to read, write, and execute for the user, and read and execute for group and others:
Summary
- Symbolic Mode: Uses letters and operators to modify permissions, allowing for more granular control.
- Numeric Mode: Uses a three-digit number to set permissions, providing a quick way to apply multiple permissions at once.
Both modes are effective for managing file permissions in Linux, and you can choose the one that best fits your needs.
