Here’s a cheat sheet for the chmod
command in Unix/Linux:
The chmod
command is used to change the permissions of a file or directory.
Syntax
chmod [options] permissions file
Options
-c
: Output results only if changes are made.-f
: Suppress most error messages.-R
: Recursively change permissions of directories and their contents.-v
: Output a diagnostic for every file processed.
Permission Symbols
u
: User/Owner.g
: Group.o
: Other.a
: All (u, g, and o combined).
Permission Types
r
: Read.w
: Write.x
: Execute.
Permission Notation
+
: Add permission.-
: Remove permission.=
: Set permission.
Examples
Grant read and write permission to the owner:
chmod u+rw file
Grant read and execute permission to the owner, and read permission to the group:
chmod u+rx,g+r file
Remove write permission from the others:
chmod o-w file
Set read, write, and execute permissions for the owner, and read-only for others:
chmod u+rwx,o+r file
Recursively give read and execute permissions to all files and directories in a directory:
chmod -R a+rx directory
Use octal notation to set permissions (e.g., read and write for the owner, and read-only for others):
chmod 644 file
Octal Permission Values
0
: No permissions.1
: Execute permission.2
: Write permission.3
: Write and execute permissions.4
: Read permission.5
: Read and execute permissions.6
: Read and write permissions.7
: Read, write, and execute permissions.
Common Octal Values
755
: Owner has read, write, and execute. Group and others have read and execute.644
: Owner has read and write. Group and others have read.
Note: Make sure to replace “file” and “directory” with the actual file or directory name in the examples.
Feel free to customize the commands based on your specific needs and file permissions requirements.