# Linux commands: chown

> Learn how the Linux chown command changes the owner of a file or directory, sets owner and group at once, and applies changes recursively with the -R flag.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-09-22 | Topics: [CLI](https://flaviocopes.com/tags/cli/) | Canonical: https://flaviocopes.com/linux-command-chown/

Every file/directory in an Operating System like Linux or macOS (and every UNIX systems in general) has an **owner**.

The owner of a file can do everything with it. It can decide the fate of that file.

The owner (and the `root` user) can change the owner to another user, too, using the `chown` command:

```bash
chown <owner> <file>
```

Like this:

```bash
chown flavio test.txt
```

For example if you have a file that's owned by `root`, you can't write to it as another user:

![Terminal showing Permission denied error when trying to write to test.txt file as non-owner user](https://flaviocopes.com/images/linux-command-chown/Screen_Shot_2020-09-03_at_18.40.49.png)

You can use `chown` to transfer the ownership to you:

![Terminal showing successful chown command transferring test.txt ownership to flavio user](https://flaviocopes.com/images/linux-command-chown/Screen_Shot_2020-09-03_at_18.40.58.png)

It's rather common to have the need to change the ownership of a directory, and recursively all the files contained, plus all the subdirectories and the files contained in them, too.

You can do so using the `-R` flag:

```bash
chown -R <owner> <file>
```

Files/directories don't just have an owner, they also have a **group**. Through this command you can change that simultaneously while you change the owner:

```bash
chown <owner>:<group> <file>
```

Example:

```bash
chown flavio:users test.txt
```

You can also just change the group of a file using the `chgrp` command:

```bash
chgrp <group> <filename>
```

> The `chown` command works on Linux, macOS, WSL, and anywhere you have a UNIX environment
