Cheat Sheet #day70 - chmod
chmod
Command Cheatsheet
The chmod
command in Unix-like systems is used to change permissions (mode) of files and directories. It allows users to specify who can read, write, or execute files. Here’s a quick reference guide:
Basic Syntax
chmod [OPTIONS] MODE FILE...
Common Options
-c
,--changes
: Report only when a change is made.chmod -c u+x file.txt
-f
,--silent
,--quiet
: Suppress most error messages.chmod -f 755 file.txt
-v
,--verbose
: Output a diagnostic for every file processed.chmod -v g-w file.txt
Mode
The mode consists of three parts:
[ugoa]
: User, Group, Other, All.[+-=]
: Add, Remove, Set exactly.[rwxXst]
: Read, Write, eXecute, execute only if the file is a directory or already has execute permission for some user (X), Sticky bit, Setuid, Setgid.
Examples
Set permissions explicitly (e.g., read, write, execute for user):
chmod u=rwx file.txt
Add permissions (e.g., add execute permission for group):
chmod g+x file.txt
Remove permissions (e.g., remove write permission for others):
chmod o-w file.txt
Set permissions numerically (e.g., set read, write, execute for user and read, execute for group and others):
chmod 755 file.txt
Recursive change (e.g., change permissions for all files in a directory):
chmod -R u+rwX directory/
Additional Information
Help option:
chmod --help
View manual page for
chmod
:man chmod
The chmod
command is essential for managing file and directory permissions in Unix-like systems, allowing users to control access to files based on user, group, and others. For more detailed options and usage scenarios, refer to the man
page or use chmod --help
.
Subscribe to my newsletter
Read articles from Cloud Tuned directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by