Files
freeCodeCamp/guide/english/bash/bash-chmod/index.md
zerandomalt ff6c300335 Added usages (#20035)
* Added usages

Added usages in the style of other files in the directory.

* Complete file overhaul.

Added details on how all of the three different modes are used. Added commonly used arguments section with seven arguments and how to use them. Added an examples section with three examples and explanations of them. Added a link to the SS64 page. Also made sure that the formatting is more consistent with the rest of the directory.

* Basic editting.

Removed hyphens before user (group) and read/write options because `-` is not required in front of the user (group) option and has a specific meaning (to remove) for the read/write options.

* Additional editing and formatting.

* Reworded the sentence for using a combination of numeric permission arguments.
* Changed the sentence that introduces commonly used arguments to a subheading.
2018-11-03 18:08:31 -04:00

1.8 KiB

title
title
Bash chmod

Bash command: chmod

The chmod command is used to change file permissions for both files and directories.

The standard mode is used via the arguments listed below in the commonly used arguments section.

The numeric mode is dictated by three numbers the user, group, and others, in that order.

  • 4 stands for "read",
  • 2 stands for "write",
  • 1 stands for "execute", and
  • 0 stands for "no permission."

You can also use a combination of these numbers; for example 7 would give all permissions, 6 would give read and write permissions, and 5 would give read and execute permissions.

The reference mode is used by specifying a file for reference and the targeted file. The targeted file then takes on the permissions of the reference file.

Usage

chmod [options] mode[,mode] file1 [file2 ...]
chmod [Options] Numeric_Mode file1 [file2 ...]
chmod [Options] --reference=RFile file1 [file2 ...]

Commonly Used Arguments

The first arguments are the user's permissions that will be targeted. These are followed by a '+' to add permission, '-' to remove permission or '=' to set as the only permissions.

  • u: The user who owns it.
  • g: Other users in the files' group.
  • o: Other users not in the files' group.
  • a: All users.

The second arguments dictate the permissions given.

  • r: Read permission.
  • w: Write permission.
  • x: Execute permission.

Examples

chmod 754 file1.txt

Gives the user all permissions, the files group read and execute, and all others read.

chmod u+x file1.txt

Gives the user/owner the permission to execute the file.

chmod -reference=file1.txt file2.txt

Gives file2 the same permissions that file1 has.

More Information: