How To Chown Recursively In Linux?


Linux files and folders have owners. Owners are required to control permissions. Which user can access which files. The user root created file will be owned by the user root. But what will happen we want to change the owner.

Simply Recursively Change Files and Directories Owner User and Group

We can change files and folders owner user and owner group with the recursive option -R. In this example, we will change the owner user and group files and folders located in the /home/ismail into ismail. We will also use the sudo in order to change all files and folders without error by using root administrative power.

$ sudo chown -R ismail:ismail /home/ismail/

We can check the new owner user and group with

$ ls -l /home/ismail
Simply Recursively Change Files and Directories Owner User and Group
Simply Recursively Change Files and Directories Owner User and Group

We will change the owner and group which is specified with ismail:ismail  in /home/ismail directory recursively. Keep in mind that to change owner user and a group of files we need root privileges.

Change Ownership Of Specified File Type or Extension

While changing owner users and groups we can specify file types to recursively change. We use find command to find specified file type for specified path recursively and send these files as input to chown command.

$ find /home/ismail -name '*.pdf' -exec sudo chown ismail:ismail {} \;
Specify File Types
Specify File Types

In this example find command is searching in /home/ismail for pdf extensions and run chown command for all files it founds.

LEARN MORE  What Is mtime In Linux and Find Command?

Leave a Comment