> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Change Ownership of Files and Folders Recursively
- URL: https://linuxhandbook.com/chown-recursively/
- Published: 2022-05-30T09:45:15.000Z
- Updated: 2022-05-30T09:45:15.000Z
- Description: Learn how to use the chown command to recursively change the user and group ownership of files and directories in Linux command line.
- Author: Abhishek Prakash
- Tags: Tips

You can [use the chown command in Linux to change the ownership of the file(s) and directories](https://linuxhandbook.com/chown-command/). It's quite simple to use.

```
chown owner_name file_or_folder
```

The problem arrives when you change the ownership of a directory, its content remains unchanged. The solution is not too complicated as well.

To change the ownership of all the contents of a directory, you can **use the recursive option -R with chown command:**

```
chown -R owner_name folder_name
```

If you want to change both owner and group recursively, you can use it in the following manner:

```
chown -R owner_name:group_name folder_name
```

Let's see it in detail and also see how you can change user and group recursively. Things are a lot easier to understand if you are familiar with the [concept of file ownership and permission](https://linuxhandbook.com/linux-file-permissions/).

⚠️

You'll need to be root or use sudo to change ownership of files.

## chown recursively

To recursively change the ownership of a directory, use it like this:

```
chown -R new_owner_name directory_name
```

If you have to change the ownership of multiple directories with their contents, you can do it in the same line:

```
chown -R new_owner_name directory1 directory2 directory3
```

**Let me show that with a sample example**. I have a directory named new\_dir with some content in it. This directory and its content are owned by the root user.

```
root@learnubuntu:~# ls -l /home/abhi/
total 4
drwxr-xr-x 3 root root 4096 May 30 07:30 new_dir
root@learnubuntu:~# ls -l /home/abhi/new_dir/
total 20
-rw-r--r-- 1 root root 12813 May 30 07:30 new.txt
drwxr-xr-x 2 root root  4096 May 30 07:30 one_more_dir
```

When I change the ownership of the new\_dir, its ownership is changed:

```
root@learnubuntu:~# chown abhi /home/abhi/new_dir
root@learnubuntu:~# ls -l /home/abhi/
total 4
drwxr-xr-x 3 abhi root 4096 May 30 07:30 new_dir

```

But the files and folders inside it are still owned by root.

```
root@learnubuntu:~# ls -l /home/abhi/new_dir/
total 20
-rw-r--r-- 1 root root 12813 May 30 07:30 new.txt
drwxr-xr-x 2 root root  4096 May 30 07:30 one_more_dir

```

Now, if I use the recursive option -R with chown command, it changes the ownership for everything inside the specified directory, not just the directory.

```
root@learnubuntu:~# chown -R abhi /home/abhi/new_dir
root@learnubuntu:~# ls -l /home/abhi/new_dir/
total 20
-rw-r--r-- 1 abhi root 12813 May 30 07:30 new.txt
drwxr-xr-x 2 abhi root  4096 May 30 07:30 one_more_dir
```

![Example of using chwon recursively](https://linuxhandbook.com/content/images/2022/05/chown-recursive-option.webp)

## Change both owner and group recursively

The chown command allows you to change the owner as well as the group of files.

To recursively change the owner and group of a directory and all its content, use the chown command like this:

```
chown -R user_name:group_name directory_name
```

You can use the same for changing the ownership of multiple folders: 

```
chown -R user_name:group_name dir1 dir2
```

Not too difficult, eh?

## Conclusion

Recently, I moved a self-hosted Ghost instance to a new server launched with [DigitalOcean](https://m.do.co/c/d58840562553?ref=linuxhandbook.com)'s 1-click deployment. I had to upload the entire images folder from the backup (downloaded on the local system) to the new server. The system required changing the ownership of this image folder from root to ghost. 

This method saved me the trouble. I hope this quick little tutorial helps you as well.

I highly recommend brushing up the basics of file permissions and ownership.

[Linux File Permissions and Ownership Explained with ExamplesLinux file permissions explained in simpler terms. Also learn how to change the file permissions and ownership in Linux in this detailed beginner’s guide.![](https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png)Linux HandbookAbhishek Prakash![](https://linuxhandbook.com/content/images/2020/06/linux-file-permission-featured.jpeg)](https://linuxhandbook.com/linux-file-permissions/)

It's one of the essential Linux concepts you must know.