The chmod command in Unix-like operating systems is used to change the permissions of a file or directory. This cheat sheet covers essential chmod commands for managing file and directory permissions.
Introduction:
chmod is a command-line utility that allows users to change the permissions of files and directories on Unix-based systems. It uses a symbolic or octal notation to specify permission settings.
Basic Commands:
Command
Description
chmod [permissions] [file/directory]
Change permissions using symbolic notation.
chmod [octal_permissions] [file/directory]
Change permissions using octal notation.
chmod +[permission] [file/directory]
Add a specific permission.
chmod -[permission] [file/directory]
Remove a specific permission.
Symbolic Notation:
Symbol
Permission
u
User/Owner
g
Group
o
Others
a
All (u+g+o)
r
Read
w
Write
x
Execute
Examples – Symbolic Notation:
Command
Description
chmod u+r file.txt
Add read permission for the owner.
chmod go-w directory/
Remove write permission for group and others.
chmod a+x script.sh
Add execute permission for all users.
Octal Notation:
Octal
Permission
4
Read
2
Write
1
Execute
0
No Permission
Examples – Octal Notation:
Command
Description
chmod 644 file.txt
Give read and write permission to the owner and read-only permission to others.
chmod 755 script.sh
Give read, write, and execute permission to the owner, and read/execute permission to group and others.
chmod 600 sensitive_file.txt
Restrict permissions to read and write only for the owner.
Recursive Changes:
Command
Description
chmod -R [permissions] [directory]
Recursively change permissions for a directory and its contents.
The chmod command is a powerful tool for managing file and directory permissions on Unix-based systems. This cheat sheet provides essential commands using both symbolic and octal notation, covering basic permissions, recursive changes, special permissions, and more. Whether you are a regular user or a system administrator, understanding these chmod commands will help you control access to files and directories effectively.