> For the complete documentation index, see [llms.txt](https://igb.mit.edu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://igb.mit.edu/mini-courses/introduction-to-unix/files/file-ownership/change-file-ownership-and-permissions.md).

# Change File Ownership and Permissions

To change the owners of a file, you can use the following commands:

* `chown`
  * This changes the user who owns a particular file or directory.
* `chgrp`
  * This changes the group who owns a particular file or directory.

To change the permissions that the owners of a file have, you use the `chmod` command.

`chmod` takes two arguments: the permissions to give a file, and the file to change the permissions of. The permissions are represented as a 3-digit number, where each digit represents the permissions to give the user, group, or others, respectively.

Read, write, and execute permissions are represented by the following numbers:

* r - 4
* w - 2
* x - 1

If you want to give someone multiple permissions, you add the numeric representations of those permissions together. For example:

* Read, write, execute (rwx) permissions = (4 + 2 + 1) = 7
* Write, execute (\_wx) permissions = (2 + 1) = 3

So let's say you want to give a file the following permissions:

* The user that owns the file should be able to read, write, and execute the file. rwx = (4 + 2 + 1) = 7
* The group that owns the file should be able to read and execute the file. r\_x = (4 + 1) = 5
* Anyone else should have no permissions for the file. \_\_\_ = 0

The you'd run the following command:

```bash
chmod 750 arrayDat.txt
```

Remembering the syntax for this command can be quite cumbersome, so I recommend using a third-party website such as <https://quickref.me/chmod>.
