LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

chmod

change file access permissions

TLDR

Make file executable
$ chmod +x [script.sh]
copy
Set specific permissions
$ chmod 755 [file]
copy
Remove write permission
$ chmod -w [file]
copy
Recursive change
$ chmod -R 755 [directory/]
copy
Set permissions symbolically
$ chmod u=rwx,g=rx,o=r [file]
copy

SYNOPSIS

chmod [options] mode file...

DESCRIPTION

chmod (change mode) modifies file access permissions. It controls read, write, and execute permissions for three classes of users: the file owner (user), the file's group, and all other users.Permissions can be specified in two ways: numeric (octal) mode using digits 0-7, or symbolic mode using letters (u/g/o/a, +/-/=, r/w/x). Numeric mode sets all permissions at once, while symbolic mode allows adding or removing individual permissions. The command is fundamental to Unix file security and access control.

PARAMETERS

-R, --recursive

Change files and directories recursively
-v, --verbose
Verbose output
-c, --changes
Report only changes
--reference=file
Use permissions from reference file

NUMERIC MODE

Octal digits (0-7):- 4 - Read (r)- 2 - Write (w)- 1 - Execute (x)Common modes:- 755 - rwxr-xr-x (owner full, others read/execute)- 644 - rw-r--r-- (owner read/write, others read)- 600 - rw------- (owner only)- 777 - rwxrwxrwx (all permissions, usually bad idea)

SYMBOLIC MODE

Format: [ugoa][+-=][rwxXst]Who:- u - User (owner)- g - Group- o - Others- a - AllOperation:- + - Add permission- - - Remove permission- = - Set exact permissionPermissions:- r - Read- w - Write- x - Execute- X - Execute only if directory- s - Setuid/setgid- t - Sticky bit

WORKFLOW

$ # Make script executable
chmod +x script.sh

# Set standard file permissions
chmod 644 file.txt

# Set directory permissions
chmod 755 directory/

# Recursive change
chmod -R 755 public_html/

# Remove write for group and others
chmod go-w file.txt

# Add execute for all
chmod a+x program

# Set exact permissions
chmod u=rwx,g=rx,o= private_script
copy

SPECIAL MODES

Setuid (4000):

Run as file owner
Setgid (2000):
Run as file group or inherit directory group
Sticky (1000):
Only owner can delete (common for /tmp)
Example: `chmod 4755 program` (setuid + rwxr-xr-x)

INSTALL

sudo apt install coreutils
copy
sudo dnf install coreutils
copy
sudo pacman -S coreutils
copy
sudo apk add coreutils
copy
sudo zypper install coreutils
copy
brew install coreutils
copy
nix profile install nixpkgs#coreutils
copy

CAVEATS

Requires ownership or root privileges. 777 permissions are security risk. Recursive changes can break systems. Symbolic links not affected (use chmod -h on some systems). Execute on files vs directories different meaning.

HISTORY

chmod has been part of Unix since the early 1970s, implementing the Unix permission model designed by Dennis Ritchie and Ken Thompson.

SEE ALSO

chown(1), chgrp(1), umask(1), ls(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid