# Cheat Sheet #day70 - chmod

### `chmod` Command Cheatsheet

The `chmod` command in Unix-like systems is used to change permissions (mode) of files and directories. It allows users to specify who can read, write, or execute files. Here’s a quick reference guide:

#### Basic Syntax

```sh
chmod [OPTIONS] MODE FILE...
```

#### Common Options

* `-c`, `--changes`: Report only when a change is made.
    
    ```sh
    chmod -c u+x file.txt
    ```
    
* `-f`, `--silent`, `--quiet`: Suppress most error messages.
    
    ```sh
    chmod -f 755 file.txt
    ```
    
* `-v`, `--verbose`: Output a diagnostic for every file processed.
    
    ```sh
    chmod -v g-w file.txt
    ```
    

#### Mode

The mode consists of three parts:

* `[ugoa]`: User, Group, Other, All.
    
* `[+-=]`: Add, Remove, Set exactly.
    
* `[rwxXst]`: Read, Write, eXecute, execute only if the file is a directory or already has execute permission for some user (X), Sticky bit, Setuid, Setgid.
    

#### Examples

1. **Set permissions explicitly (e.g., read, write, execute for user):**
    
    ```sh
    chmod u=rwx file.txt
    ```
    
2. **Add permissions (e.g., add execute permission for group):**
    
    ```sh
    chmod g+x file.txt
    ```
    
3. **Remove permissions (e.g., remove write permission for others):**
    
    ```sh
    chmod o-w file.txt
    ```
    
4. **Set permissions numerically (e.g., set read, write, execute for user and read, execute for group and others):**
    
    ```sh
    chmod 755 file.txt
    ```
    
5. **Recursive change (e.g., change permissions for all files in a directory):**
    
    ```sh
    chmod -R u+rwX directory/
    ```
    

#### Additional Information

* **Help option:**
    
    ```sh
    chmod --help
    ```
    
* **View manual page for** `chmod`:
    
    ```sh
    man chmod
    ```
    

The `chmod` command is essential for managing file and directory permissions in Unix-like systems, allowing users to control access to files based on user, group, and others. For more detailed options and usage scenarios, refer to the `man` page or use `chmod --help`.
