HxHippy

chmod

Change file mode bits (permissions)

Overview

Changes the file mode bits of each given file according to mode, which can be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bits.

Syntax

chmod [OPTION]... MODE[,MODE]... FILE... 
chmod [OPTION]... OCTAL-MODE FILE... 
chmod [OPTION]... --reference=RFILE FILE...

Common Options

-R, --recursive

Change files and directories recursively.

-v, --verbose

Output a diagnostic for every file processed.

-c, --changes

Like verbose but report only when a change is made.

--reference=RFILE

Use RFILE's mode instead of MODE values.

--silent, --quiet

Suppress most error messages.

Symbolic Modes: u (user), g (group), o (others), a (all)

Classes for symbolic mode.

Symbolic Operators: + (add), - (remove), = (set exactly)

Operators for symbolic mode.

Symbolic Permissions: r (read), w (write), x (execute), X (special execute), s (setuid/gid), t (sticky)

Permissions for symbolic mode.

Examples

$ chmod u+x script.sh

Makes script.sh executable by the user/owner.

$ chmod 755 myfile.txt

Sets read/write/execute for user, and read/execute for group and others (octal).

$ chmod g-w,o-w important_data

Removes write permission for the group and others from important_data.

$ chmod a=r public_file.txt

Sets read-only permission for everyone (user, group, and others).

$ chmod -R u+rw,g+r,o+r project_dir/

Recursively sets read/write for user, and read-only for group and others for all files/directories in project_dir/.

$ chmod --reference=template.sh new_script.sh

Copies permissions from template.sh to new_script.sh.

$ chmod u=rwx,g=rx,o=rx myscript

Sets user to read, write, execute; group to read, execute; others to read, execute.

permissionsaccessrightsfiledirectorysecuritymodechmod