The chown command changes user ownership(owner) and group ownership(group) of specified files and directories. User ownership is specified by user name or user ID, and group ownership is specified by group name or group ID.
Change user ownership. First, check user ownership and group ownership with “ls command”.
[vagrant@localhost symbolic]$ ls -l
合計 4
drwxr-xr-x 2 vagrant vagrant 4096 1月 27 20:32 2019 backupdir
lrwxrwxrwx 1 vagrant vagrant 10 1月 27 16:51 2019 latest -> text03.txt
lrwxrwxrwx 1 vagrant vagrant 12 1月 27 16:47 2019 latest~ -> mylist02.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist01.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:43 2019 mylist02.txt
-rw-rw-r– 1 vagrant vagrant 0 1月 27 16:50 2019 mylist03.txt
User ownership is “vagrant”, group ownership is also “vagrant”.
Change user ownership
Try changing the user ownership from “vagrant” to “root” without specifying a group. Execute the chown command as follows.
[vagrant@localhost symbolic]$ chown root mylist01.txt
chown: `mylist01.txt’ の所有権を変更中: 許可されていない操作です
It seems that root privilege is requried for chown execution.
[vagrant@localhost symbolic]$ sudo chown root mylist01.txt
[vagrant@localhost symbolic]$ ls -l mylist01.txt
-rw-rw-r– 1 root vagrant 0 1月 27 16:43 2019 mylist01.txt
Change user ownership and group ownership
Specify users and groups, and execute chown command. Between the users and the group, put : (semicolon).
[vagrant@localhost symbolic]$ sudo chown root:root mylist02.txt
[vagrant@localhost symbolic]$ ls -l mylist02.txt
-rw-rw-r– 1 root root 0 1月 27 16:43 2019 mylist02.txt
Directory ownership
To change directory ownership recursively, use option -R.
[vagrant@localhost app]$ sudo chown -hR root:root symbolic