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.
This commit is contained in:
zerandomalt
2018-11-03 22:08:31 +00:00
committed by Martin Payne
parent 0067470aeb
commit ff6c300335

View File

@@ -4,20 +4,62 @@ title: Bash chmod
## Bash command: chmod
**Change the permissions of a File/Directory**, for example `chmod u+x hello.py`. (Gives the user the permission to execute the file)
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
**Change the permissions of a File/Directory**
```bash
chmod [options] mode[,mode] file1 [file2 ...]
```
```bash
chmod [Options] Numeric_Mode file1 [file2 ...]
```
```bash
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
```bash
chmod [permission] [file_names]
chmod 754 file1.txt
```
permission can be r+w or r+w+x ...etc
Gives the user all permissions, the files group read and execute, and all others read.
```bash
chmod u+x file1.txt
```
Gives the user/owner the permission to execute the file.
```bash
chmod -reference=file1.txt file2.txt
```
Gives file2 the same permissions that file1 has.
* r = read
* w = write
* x = execute
### More Information:
#### More Information:
* [Wikipedia](https://en.wikipedia.org/wiki/Chmod)
* [SS64](https://ss64.com/bash/chmod.html)