zl程序教程

您现在的位置是:首页 >  系统

当前栏目

Linux命令之chgrp详解程序员

Linux命令程序员 详解 chgrp
2023-06-13 09:20:05 时间

chgrp [选项] … reference=RFILE FILE …

chgrp命令是用来改变文件的组所有权。将改变每一个FILE的所属组为GROUP。使用 reference时,将改变每个FILE的所属组为RFILE的所属组。

(1).选项

-c,--changes 类似verbose,但仅在进行更改时报告。 

-f,--silent,--quiet 不列出大多数错误信息 

-v,--verbose 为每个处理的文件输出诊断信息。 

--dereference 影响每个符号链接的引用(这是默认值),而不是符号链接本身 

-h,--no-derference 影响符号链接本身而不是任何引用的文件(仅在可以更改符号链接的所有权的系统上有用) 

--no-preserve-root 要特别对待’/’(根目录?)(默认) 

--preserve-root 无法以’/’(根目录?)递归操作 

--reference=RFILE 使用RFILE的组而不是指定GROUP值 

--help 显示帮助并退出 

--version 打印版本信息并退出 

-R,--recursive 以递归方式操作文件和目录

当-R选项被指定时,以下选项修改了如何遍历层次结构。如果指定了多个选项,只有最后一个生效。

-H 如果一个命令行的参数是符号链接,遍历它 

-L 遍历目录里遇到的每一个符号链接 

-P 不要遍历任何符号链接(默认)

(2).实例

 更改文件1.txt的用户组

[[email protected] xf]# ls -l 

总用量 0 

-rw-rw-r--. 1 xf xf 0 11月 7 11:00 1.txt 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 公共 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 模板 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 视频 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 图片 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 文档 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 下载 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 音乐 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 桌面 

[[email protected] xf]# chgrp -v root 1.txt 

changed group of "1.txt" from xf to root 

[[email protected] xf]# ls -l 1.txt 

-rw-rw-r--. 1 xf root 0 11月 7 11:00 1.txt 

参照文件1.txt的用户组更改文件2.txt的用户组

[[email protected] xf]# ls -l 

总用量 0 

-rw-rw-r--. 1 xf root 0 11月 7 11:00 1.txt 

-rw-rw-r--. 1 xf xf 0 11月 7 11:04 2.txt 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 公共 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 模板 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 视频 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 图片 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 文档 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 下载 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 音乐 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 桌面 

[[email protected] xf]# chgrp -v --reference=1.txt 2.txt 

changed group of "2.txt" from xf to root 

[[email protected] xf]# ls -l 2.txt 

-rw-rw-r--. 1 xf root 0 11月 7 11:04 2.txt 

递归指定目录,更改其下所有用户组,以及其本身的用户组

[[email protected] xf]# ls -l 

总用量 0 

drwxrwxr-x. 3 xf xf 47 11月 7 11:25 newDir 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 公共 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 模板 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 视频 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 图片 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 文档 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 下载 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 音乐 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 桌面 

[[email protected] xf]# ls -l newDir/ 

总用量 0 

-rw-rw-r--. 1 xf xf 0 11月 7 11:25 3.txt 

-rw-rw-r--. 1 xf xf 0 11月 7 11:25 4.txt 

drwxrwxr-x. 2 xf xf 32 11月 7 11:25 newDir1 

[[email protected] xf]# ls -l newDir/newDir1/ 

总用量 0 

-rw-rw-r--. 1 xf xf 0 11月 7 11:25 5.txt 

-rw-rw-r--. 1 xf xf 0 11月 7 11:25 6.txt 

[[email protected] newDir1]# cd /home/xf 

[[email protected] xf]# chgrp -vR root newDir/ 

changed group of "newDir/3.txt" from xf to root 

changed group of "newDir/4.txt" from xf to root 

changed group of "newDir/newDir1/5.txt" from xf to root 

changed group of "newDir/newDir1/6.txt" from xf to root 

changed group of "newDir/newDir1" from xf to root 

changed group of "newDir/" from xf to root 

[[email protected] xf]# ls -l 

总用量 0 

drwxrwxr-x. 3 xf root 47 11月 7 11:25 newDir 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 公共 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 模板 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 视频 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 图片 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 文档 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 下载 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 音乐 

drwxr-xr-x. 2 xf xf 6 9月 6 11:43 桌面 

[[email protected] xf]# ls -l newDir/ 

总用量 0 

-rw-rw-r--. 1 xf root 0 11月 7 11:25 3.txt 

-rw-rw-r--. 1 xf root 0 11月 7 11:25 4.txt 

drwxrwxr-x. 2 xf root 32 11月 7 11:25 newDir1 

[[email protected] xf]# ls -l newDir/newDir1/ 

总用量 0 

-rw-rw-r--. 1 xf root 0 11月 7 11:25 5.txt 

-rw-rw-r--. 1 xf root 0 11月 7 11:25 6.txt 

也可以用群组识别码来代替组名,详细可看/etc/group

[[email protected] xf]# ls -l 7.txt 

-rw-rw-r--. 1 xf xf 0 11月 7 11:46 7.txt 

[[email protected] xf]# chgrp -v 5 7.txt 

changed group of "7.txt" from xf to 5 

[[email protected] xf]# ls -l 7.txt 

-rw-rw-r--. 1 xf tty 0 11月 7 11:46 7.txt

群组识别码

[[email protected] ~]$ cat /etc/group 

root:x:0: 

bin:x:1: 

daemon:x:2: 

sys:x:3: 

adm:x:4: 

tty:x:5: 

disk:x:6: 

lp:x:7: 

mem:x:8: 

kmem:x:9: 

wheel:x:10:xf 

cdrom:x:11: 

mail:x:12:postfix 

man:x:15: 

dialout:x:18: 

floppy:x:19: 

games:x:20: 

tape:x:33: 

video:x:39: 

ftp:x:50: 

lock:x:54: 

audio:x:63: 

nobody:x:99: 

users:x:100: 

utmp:x:22: 

utempter:x:35: 

stapusr:x:156: 

stapsys:x:157: 

stapdev:x:158: 

input:x:999: 

systemd-journal:x:190: 

systemd-network:x:192: 

dbus:x:81: 

polkitd:x:998: 

printadmin:x:997: 

libstoragemgmt:x:996: 

rpc:x:32: 

colord:x:995: 

dip:x:40: 

cgred:x:994: 

ssh_keys:x:993: 

saslauth:x:76: 

abrt:x:173: 

setroubleshoot:x:992: 

rtkit:x:172: 

chrony:x:991: 

rpcuser:x:29: 

nfsnobody:x:65534: 

kvm:x:36:qemu 

qemu:x:107: 

unbound:x:990: 

gluster:x:989: 

tss:x:59: 

libvirt:x:988: 

usbmuxd:x:113: 

geoclue:x:987: 

radvd:x:75: 

pulse-access:x:986: 

pulse-rt:x:985: 

pulse:x:171: 

gdm:x:42: 

gnome-initial-setup:x:984: 

sshd:x:74: 

avahi:x:70: 

slocate:x:21: 

postdrop:x:90: 

postfix:x:89: 

ntp:x:38: 

tcpdump:x:72: 

xf:x:1000:

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/2886.html

服务器部署程序员系统优化网站设置运维