You can change file and directory permissions in Linux using the chmod command. Here are the common methods to do so:
1. Using Symbolic Notation:
You can specify permissions using letters:
u: User (owner)g: Groupo: Othersa: All (user, group, and others)
You can add (+), remove (-), or set (=) permissions.
Examples:
To add execute permission for the owner:
chmod u+x filenameTo remove write permission for the group:
chmod g-w filenameTo set read and write permissions for the owner and remove all permissions for others:
chmod u=rw, o= filename
2. Using Numeric (Octal) Notation:
Permissions can also be set using numbers, where:
4: Read2: Write1: Execute
You combine these numbers for each user category (owner, group, others).
Examples:
To set permissions to
rwxr-xr--(755):chmod 755 filenameTo set permissions to
rw-r-----(640):chmod 640 filename
3. Recursively Changing Permissions:
To change permissions for a directory and all its contents, use the -R option:
chmod -R 755 directory_name
This command sets the permissions for the directory and all files and subdirectories within it.
If you have any further questions or need more examples, feel free to ask!
