cheat.sheets:chmod
# chmod
# Change file mode bits
# Give the [u]ser who owns a file the right to e[x]ecute it.
chmod u+x PATH
# Give the [u]ser rights to [r]ead and [w]rite to a file/directory.
chmod u+rw PATH
# Remove e[x]ecutable rights from the [g]roup.
chmod g-x PATH
# Give [a]ll users rights to [r]ead and e[x]ecute.
chmod a+rx PATH
# Give [o]thers (not in the file owner's group) the same rights as the [g]roup.
chmod o=g PATH
# Remove all rights from [o]thers.
chmod o= PATH
# Change permissions recursively, allowing [g]roup and [o]thers to [w]rite.
chmod -R g+w,o+w PATH
# Set access rights using numeric (octal) form.
chmod 750 PATH
# Add the execute permission bit to directories only. This works because the
# 'X' is uppercase, meaning only directories will be executable. However, if
# an existing file is executable, this bit will not be removed.
chmod a+X PATH
# Convert string representation of the access right into numeric form and back.
curl cheat.sh/chmod/750
curl cheat.sh/chmod/rwxr-x---
cheat:chmod
# Add execute for all (myscript.sh)
chmod a+x myscript.sh
# Set user to read/write/execute, group/global to read only (myscript.sh), symbolic mode
chmod u=rwx, go=r myscript.sh
# Remove write from user/group/global (myscript.sh), symbolic mode
chmod a-w myscript.sh
# Remove read/write/execute from user/group/global (myscript.sh), symbolic mode
chmod = myscript.sh
# Set user to read/write and group/global read (myscript.sh), octal notation
chmod 644 myscript.sh
# Set user to read/write/execute and group/global read/execute (myscript.sh), octal notation
chmod 755 myscript.sh
# Set user/group/global to read/write (myscript.sh), octal notation
chmod 666 myscript.sh
# Roles
u - user (owner of the file)
g - group (members of file's group)
o - global (all users who are not owner and not part of group)
a - all (all 3 roles above)
# Numeric representations
7 - full (rwx)
6 - read and write (rw-)
5 - read and execute (r-x)
4 - read only (r--)
3 - write and execute (-wx)
2 - write only (-w-)
1 - execute only (--x)
0 - none (---)
# Delete ACL number 0 (MacOS):
# See: `man -M /usr/share/man chmod`
/bin/chmod -a# 0 /path/to/file
tldr:chmod
# chmod
# Change the access permissions of a file or directory.
# More information: <https://www.gnu.org/software/coreutils/chmod>.
# Give the [u]ser who owns a file the right to e[x]ecute it:
chmod u+x path/to/file
# Give the [u]ser rights to [r]ead and [w]rite to a file/directory:
chmod u+rw path/to/file_or_directory
# Remove e[x]ecutable rights from the [g]roup:
chmod g-x path/to/file
# Give [a]ll users rights to [r]ead and e[x]ecute:
chmod a+rx path/to/file
# Give [o]thers (not in the file owner's group) the same rights as the [g]roup:
chmod o=g path/to/file
# Remove all rights from [o]thers:
chmod o= path/to/file
# Change permissions recursively giving [g]roup and [o]thers the ability to [w]rite:
chmod -R g+w,o+w path/to/directory
# Recursively give [a]ll users [r]ead permissions to files and e[X]ecute permissions to sub-directories within a directory:
chmod -R a+rX path/to/directory
$
cheat.sh