、使用 chown命令 更改文件拥有者
在 shell 中,能够使用 chown命令 来改变文件全部者。 chown命令 是change owner(改变拥有者)的缩写。须要要注意的是, 用户必须是已经存在系统中的,也就是仅仅能改变为在 /etc/passwd这个文件里有记录的username称才干够 。
chown命令 的用途非常多,还能够顺便直接改动用户组的名称。
此外,假设要连文件夹下的全部子文件夹或文件同一时候更改文件拥有者的话,直接加上
-R 的參数就可以。
基本的语法:
chown [ -R] 账号名称 文件或 文件夹
chown [ -R] 账号名称: 用户组名称 文件或 文件夹
參数:
-R
都更新成为这个用户组。经常常使用在更改某一文件夹的情况。
演示样例1:
touch testfile //由 root 用户创建文件
ls testfile –l
-rw--w--w- 1 root root 0 Jun 7 19:35 testfile //文件的拥有者及拥有者级均为 root
chown yangzongde testfile //改动文件拥有者为 yangzongde
ls testfile -l
-rw--w--w- 1 yangzongde root 0 Jun 7 19:35 testfile //查看文件拥有者为 yangzongde。但组仍为 root
演示样例2:
chown bin install.log
ls -l
-rw-r--r-- 1 bin users 68495 Jun 25 08:53 install.log
chown root: root install.log
ls -l
-rw-r--r-- 1 root root 68495 Jun 25 08:53 install.log
三、使用 chgrp命令 更改文件所属用户组
在shell中,能够使用 chgrp命令 来改变文件所属用户组,该命令就是change group(改变用户组)的缩写。
须要注意的是要改变成为的用户组名称,必须在
/etc/group 里存在,否则就会显示错误。
基本的语法:
chgrp [ -R] 用户组名称 dirname/ filename
參数:
-R : 进行递归( recursive )的持续更改,即连同子文件夹下的全部文件、文件夹
都更新成为这个用户组。经常常使用在更改某一文件夹的情况。
演示样例3
ls testfile -l
-rw--w--w- 1 yangzongde root 0 Jun 7 19:35 testfile //查看文件拥有者为 yangzongde。但组为 root
chgrp yangzongde testfile //改动拥有者组为 yangzongde
ls testfile -l
-rw--w--w- 1 yangzongde yangzongde 0 Jun 7 19:35 testfile
chown root: root testfile // 使用 chown 一次性改动拥有者及组
ls testfile -l
-rw--w--w- 1 root root 0 Jun 7 19:35 testfile
演示样例4
chgrp users install.log
ls -l
-rw-r--r-- 1 root users 68495 Jun 25 08:53 install.log
演示样例5
/etc/group 里不存在的用户组
chgrp testing install.log
chgrp: invalid group name `testing' <== 出现错误信息~找不到这个用户组名~
转载于:
、使用 chown命令
更改文件拥有者
在 shell 中,能够使用 chown命令 来改变文件全部者。 chown命令 是change owner(改变拥有者)的缩写。须要要注意的是, 用户必须是已经存在系统中的,也就是仅仅能改变为在 /etc/passwd这个文件里有记录的username称才干够 。
chown命令 的用途非常多,还能够顺便直接改动用户组的名称。
此外,假设要连文件夹下的全部子文件夹或文件同一时候更改文件拥有者的话,直接加上
-R 的參数就可以。
基本的语法:
chown [ -R] 账号名称 文件或 文件夹
chown [ -R] 账号名称: 用户组名称 文件或 文件夹
參数:
-R
都更新成为这个用户组。经常常使用在更改某一文件夹的情况。
演示样例1:
touch testfile //由 root 用户创建文件
ls testfile –l
-rw--w--w- 1 root root 0 Jun 7 19:35 testfile //文件的拥有者及拥有者级均为 root
chown yangzongde testfile //改动文件拥有者为 yangzongde
ls testfile -l
-rw--w--w- 1 yangzongde root 0 Jun 7 19:35 testfile //查看文件拥有者为 yangzongde。但组仍为 root
演示样例2:
chown bin install.log
ls -l
-rw-r--r-- 1 bin users 68495 Jun 25 08:53 install.log
chown root: root install.log
ls -l
-rw-r--r-- 1 root root 68495 Jun 25 08:53 install.log
三、使用 chgrp命令 更改文件所属用户组
在shell中,能够使用 chgrp命令 来改变文件所属用户组,该命令就是change group(改变用户组)的缩写。
须要注意的是要改变成为的用户组名称,必须在
/etc/group 里存在,否则就会显示错误。
基本的语法:
chgrp [ -R] 用户组名称 dirname/ filename
參数:
-R : 进行递归( recursive )的持续更改,即连同子文件夹下的全部文件、文件夹
都更新成为这个用户组。经常常使用在更改某一文件夹的情况。
演示样例3
ls testfile -l
-rw--w--w- 1 yangzongde root 0 Jun 7 19:35 testfile //查看文件拥有者为 yangzongde。但组为 root
chgrp yangzongde testfile //改动拥有者组为 yangzongde
ls testfile -l
-rw--w--w- 1 yangzongde yangzongde 0 Jun 7 19:35 testfile
chown root: root testfile // 使用 chown 一次性改动拥有者及组
ls testfile -l
-rw--w--w- 1 root root 0 Jun 7 19:35 testfile
演示样例4
chgrp users install.log
ls -l
-rw-r--r-- 1 root users 68495 Jun 25 08:53 install.log
演示样例5
/etc/group 里不存在的用户组
chgrp testing install.log
chgrp: invalid group name `testing' <== 出现错误信息~找不到这个用户组名~