File Permission Basics
r (Read): Allows reading/viewing the contents of the file.
w (Write): Allows modifying the contents of the file.
x (Execute): Allows executing or running the file (for scripts and binaries).
Permission Groups
User (u): Owner of the file.
Group (g): Users in the file’s group.
Others (o): Users not in the file’s group.
All (a): Represents all users (u + g + o).
Symbolic Notation
+ (Add): Adds a permission.
– (Remove): Removes a permission.
= (Set): Sets the specified permissions and removes others.
Setting Permissions
chmod command:
chmod permissions filename
Examples:
chmod +x script.sh # Add execute permission
chmod u=rw,go= script # Set read and write for user, remove for group and others
Numeric Notation
4 (Read), 2 (Write), 1 (Execute):
- rwx (7): Read, write, and execute.
- rw- (6): Read and write.
- r– (4): Read only.
- –x (1): Execute only.
- — (0): No permissions.
Changing Ownership
chown command:
chown user:group filename
Viewing Permissions
ls command:
ls -l filename
Example Output:
-rwxr--r-- 1 user group 1024 Jan 1 00:00 filename
In the example output:
- The first character (
-
) represents the file type. - The next three characters (
rwx
) represent user permissions. - The next three characters (
r--
) represent group permissions. - The last three characters (
r--
) represent others’ permissions.
Special Permissions
s (Setuid/Setgid): Executes with the permissions of the file owner/group.
t (Sticky Bit): Only the file owner can delete or rename their files in a directory.
Recursive Changes
-R option with chmod:
chmod -R permissions directory
This cheat sheet covers the basics of file permissions in Unix-like systems. Adjust the commands and options according to your specific needs.