To change file permissions in Linux, you use the chmod command. This command allows you to modify the read, write, and execute permissions for the owner, group, and others.
Syntax
The basic syntax of the chmod command is:
chmod [options] mode file
Modes
You can specify permissions using either symbolic or numeric modes.
1. Symbolic Mode
In symbolic mode, you use letters to represent the permissions:
u: User (owner)g: Groupo: Othersa: All (user, group, and others)
You can add (+), remove (-), or set (=) permissions.
Examples:
-
Add execute permission for the owner:
chmod u+x filename.txt -
Remove write permission for the group:
chmod g-w filename.txt -
Set read and write permissions for all:
chmod a=rw filename.txt
2. Numeric Mode
In numeric mode, you use numbers to set permissions:
- Read (
r) = 4 - Write (
w) = 2 - Execute (
x) = 1
You add these values together for each user category (owner, group, others).
Examples:
-
Set read, write, and execute permissions for the owner, and read for group and others:
chmod 744 filename.txt -
Set read and write permissions for the owner, and read for group and others:
chmod 644 filename.txt
Viewing Permissions
After changing permissions, you can verify them using:
ls -l filename.txt
This will display the updated permissions along with other file details.
Conclusion
Changing file permissions is essential for managing access control in Linux. If you have any more questions or need further assistance, feel free to ask!
