Linux distributions provide the
chown command in order to manage file and folder ownership. By using the chmod command single or multiple files and folders ownership can be changed but this also requires root privileges. Even chmod command comes with different options and parameters one of the most used options is the recursive option which will be run given parameter on all current files and folders and their sub-files and sub-folders.
chmod Recursive Syntax
The recursive chown command has the following syntax. Where the
--recursive parameter is provided with the user or group name and the path or file information.
chown -R USER:GROUP PATH
- -R or –recursive is used to run the chown command recursively.
- USER is the username that will set the owner user of files and folders for the specified PATH.
- GROUP is the username that will set the owner user of files and folders for the specified PATH.
- PATH is the files or folder where the ownership USER and GROUP information will be changed recursively. Also, multiple PATHs can be provided by delimiting their spaces.
List Owner Users and Groups
Before changing the owner user and group information of the files and folders listing their current owner user and groups will be very useful. We will use the ls command with the -l parameter which will provide detailed information while listing files and folders.
$ ls -l
Change Owner User chown Recursively
We can change the owner user of the given path files and folder recursively. We will provide the user name, the path, and recursive information. In the following example, we will change all files and folders under the /home/ismail to the user named ismail . We will also provide the sudo command in order to provide the root privileges to prevent privilege related problems.
$ sudo -R ismail /home/ismail
We can also provides multiple paths to change owner user information recursively like below. In the following example we will change the paths /home/ismail , /var/ismail , /mnt/disk files and folders owner to the user ismail .
$ sudo -R ismail /home/ismail /var/ismail /mnt/disk
Change Owner Group chown Recursively
We can also change the owner group information for the specified path files and folders recursively with the chown command. We will provide the group information as :ismail where we will leave the user part empty.
$ sudo -R :ismail /home/ismail
Like changing the owner user recursively multiple paths can be specified in order to change given paths folders and files recursively.
$ sudo -R :ismail /home/ismail /var/ismail /mnt/disk
Change Owner User and Group chown Recursively
We can also use the chown command in order to change the given path file and folder owner user and group information recursively with a single command. We will provide both the user and group information like ismail:dev, where ismail is the user and dev, is the group name.
$ sudo -R ismail:dev /home/ismail
Also we can change multiple paths user and group information in a single command like below.
$ sudo -R ismail:dev /home/ismail /var/ismail /mnt/disk