chgrp命令用来改变文件或目录所属的用户组。

(1)用法:

    用法:  chgrp  [选项参数] [组] [文件]

或 chgrp  [选项]   组文件...   POSIX 选项: [-R] [--]

(2)功能:

    功能:  改变文件的组所有权

    (3)选项参数:

1) -c  --changes             效果类似“-v”参数,但仅回报更改的部分

2) -f  --quiet  --silent           不显示错误信息

  3) -h  --no-dereference          只对符号连接的文件作修改,而不是该其他任何相关文件

  4) -R  --recursive             递归处理,将指令目录下的所有文件及子目录一并处理

5) -v  --verbose             显示指令执行过程

6) --reference=<参考文件或目录>           把指定文件或目录的所属群组全部设成和参考文件或目录的所属群组相同

    (4)实例:

1)[root@localhost sunjimeng]# chgrp -v root Document          将Document所在组改为root

[root@localhost sunjimeng]# ll
总用量
drwxr-xr-x. sunjimeng sunjimeng 5月 : Desktop
drwxrwxr-x. sunjimeng sunjimeng 5月 : Document
drwxr-xr-x. root root 5月 : Documents
drwxr-xr-x. sunjimeng sunjimeng 5月 : Downloads
drwxrwxr-x. sunjimeng sunjimeng 5月 : findTextDir
drwxr-xr-x. sunjimeng sunjimeng 5月 : Music
drwxr-xr-x. sunjimeng sunjimeng 5月 : Pictures
drwxr-xr-x. sunjimeng sunjimeng 5月 : Public
drwxr-xr-x. sunjimeng sunjimeng 5月 : Templates
drwxr-xr-x. sunjimeng sunjimeng 5月 : Videos
[root@localhost sunjimeng]# chgrp -v root Document
changed group of "Document" from sunjimeng to root
[root@localhost sunjimeng]# ll
总用量
drwxr-xr-x. sunjimeng sunjimeng 5月 : Desktop
drwxrwxr-x. sunjimeng root 5月 : Document
drwxr-xr-x. root root 5月 : Documents
drwxr-xr-x. sunjimeng sunjimeng 5月 : Downloads
drwxrwxr-x. sunjimeng sunjimeng 5月 : findTextDir
drwxr-xr-x. sunjimeng sunjimeng 5月 : Music
drwxr-xr-x. sunjimeng sunjimeng 5月 : Pictures
drwxr-xr-x. sunjimeng sunjimeng 5月 : Public
drwxr-xr-x. sunjimeng sunjimeng 5月 : Templates
drwxr-xr-x. sunjimeng sunjimeng 5月 : Videos

2)[root@localhost Document]# chgrp -v --reference=newDir all.txt            将文件所属组设置为同某一个文件或文件夹一样

[root@localhost Document]# ll
总用量
-rw-r--r--. root root 5月 : all.txt
-rw-rw-r--. sunjimeng sunjimeng 5月 : B.text3
-rw-rw-r--. sunjimeng sunjimeng 5月 : C.text6
-rw-rw-r--. sunjimeng sunjimeng 5月 : D.text
drwxr-xr-x. root root 5月 : newDir
-rw-r--r--. root root 5月 : t1.txt
-rw-r--r--. root root 5月 : t2.txt
[root@localhost Document]# chgrp -v --reference=newDir all.txt
"all.txt" 的所属组已保留为root
[root@localhost Document]# ll
总用量
-rw-r--r--. root root 5月 : all.txt
-rw-rw-r--. sunjimeng sunjimeng 5月 : B.text3
-rw-rw-r--. sunjimeng sunjimeng 5月 : C.text6
-rw-rw-r--. sunjimeng sunjimeng 5月 : D.text
drwxr-xr-x. root root 5月 : newDir
-rw-r--r--. root root 5月 : t1.txt
-rw-r--r--. root root 5月 : t2.txt

3)[root@localhost sunjimeng]# chgrp -vR sunjimeng Document                          改变指定目录以及其子目录下的所有文件的群组属性

[root@localhost sunjimeng]# chgrp -vR sunjimeng Document
changed group of "Document/newDir/mvt1.txt" from root to sunjimeng
changed group of "Document/newDir/mvt2.txt" from root to sunjimeng
changed group of "Document/newDir/mvt3.txt" from root to sunjimeng
changed group of "Document/newDir" from root to sunjimeng
changed group of "Document/t1.txt" from root to sunjimeng
changed group of "Document/t2.txt" from root to sunjimeng
changed group of "Document/all.txt" from root to sunjimeng
"Document/B.text3" 的所属组已保留为sunjimeng
"Document/C.text6" 的所属组已保留为sunjimeng
"Document/D.text" 的所属组已保留为sunjimeng
changed group of "Document" from root to sunjimeng
[root@localhost sunjimeng]# ls -l Document
总用量
-rw-r--r--. root sunjimeng 5月 : all.txt
-rw-rw-r--. sunjimeng sunjimeng 5月 : B.text3
-rw-rw-r--. sunjimeng sunjimeng 5月 : C.text6
-rw-rw-r--. sunjimeng sunjimeng 5月 : D.text
drwxr-xr-x. root sunjimeng 5月 : newDir
-rw-r--r--. root sunjimeng 5月 : t1.txt
-rw-r--r--. root sunjimeng 5月 : t2.txt

4)[root@localhost sunjimeng]# chgrp -vR 100 Document           通过群组识别码改变文件群组属性,100为users群组的识别码,具体群组和群组识别码可以去/etc/group文件中查看

[root@localhost sunjimeng]# chgrp -vR  Document
changed group of "Document/newDir/mvt1.txt" from sunjimeng to
changed group of "Document/newDir/mvt2.txt" from sunjimeng to
changed group of "Document/newDir/mvt3.txt" from sunjimeng to
changed group of "Document/newDir" from sunjimeng to
changed group of "Document/t1.txt" from sunjimeng to
changed group of "Document/t2.txt" from sunjimeng to
changed group of "Document/all.txt" from sunjimeng to
changed group of "Document/B.text3" from sunjimeng to
changed group of "Document/C.text6" from sunjimeng to
changed group of "Document/D.text" from sunjimeng to
changed group of "Document" from sunjimeng to
[root@localhost sunjimeng]# ls -l Document
总用量
-rw-r--r--. root users 5月 : all.txt
-rw-rw-r--. sunjimeng users 5月 : B.text3
-rw-rw-r--. sunjimeng users 5月 : C.text6
-rw-rw-r--. sunjimeng users 5月 : D.text
drwxr-xr-x. root users 5月 : newDir
-rw-r--r--. root users 5月 : t1.txt
-rw-r--r--. root users 5月 : t2.txt

      群组识别码:

[root@localhost sunjimeng]# cat /etc/group
root:x::
bin:x::
daemon:x::
sys:x::
adm:x::
tty:x::
disk:x::
lp:x::
mem:x::
kmem:x::
wheel:x::
cdrom:x::
mail:x::postfix
man:x::
dialout:x::
floppy:x::
games:x::
tape:x::
video:x::
ftp:x::
lock:x::
audio:x::
nobody:x::
users:x::
utmp:x::
utempter:x::
systemd-journal:x::
dbus:x::
polkitd:x::
cgred:x::
tss:x::
colord:x::
usbmuxd:x::
dip:x::
ntp:x::
ssh_keys:x::
libstoragemgmt:x::
saslauth:x::
rpc:x::
rtkit:x::
chrony:x::
radvd:x::
rpcuser:x::
nfsnobody:x::
kvm:x::qemu
qemu:x::
abrt:x::
sssd:x::
avahi-autoipd:x::
unbound:x::
pulse-access:x::
pulse:x::
gdm:x::
gnome-initial-setup:x::
postdrop:x::
postfix:x::
sshd:x::
slocate:x::
avahi:x::
stapusr:x::
stapsys:x::
stapdev:x::
tcpdump:x::
sunjimeng:x::

5)[sunjimeng@localhost Document]$ chgrp -vf sunjimeng findDir      -v是不显示错误信息,v命令显示执行的步骤    

[root@localhost Documents]# ll
总用量
dr--r--r--. root root 5月 : findDir
drwxr-xr-x. root root 5月 : NoPdir
drwxr-xr-x. root root 5月 : Pdir
[root@localhost Documents]# exit
exit
[sunjimeng@localhost ~]$ cd Document
[sunjimeng@localhost Document]$ chgrp -v sunjimeng findDir
chgrp: 无法访问"findDir": 没有那个文件或目录
无法更改"findDir" 的所属组为sunjimeng
[sunjimeng@localhost Document]$ chgrp -vf sunjimeng findDir
无法更改"findDir" 的所属组为sunjimeng

每天一个Linux命令(25)chgrp命令的更多相关文章

  1. 【No.2】监控Linux性能25个命令行工具

    接着上一篇博文继续 [No.1]监控Linux性能25个命令行工具 10:mpstat -- 显示每个CPU的占用情况 该命令可以显示每个CPU的占用情况,如果有一个CPU占用率特别高,那么有可能是一 ...

  2. 【No.1】监控Linux性能25个命令行工具

    如果你的Linux服务器突然负载暴增,告警短信快发爆你的手机,如何在最短时间内找出Linux性能问题所在?通过以下命令或者工具可以快速定位 top vmstat lsof tcpdump netsta ...

  3. 每天一个linux命令30)--chgrp命令

    在Linux系统里,文件或目录的权限的掌控以拥有者及所属群组来管理.可以使用chgrp 指令取变更文件与目录所属群组,这种方式采用群组名称或群组识别码都可以. chgrp 命令就是change  gr ...

  4. linux常用命令:chgrp 命令

    在 lunix系统里,文件或目录的权限的掌控以拥有者及所诉群组来管理.可以使用chgrp指令变更文件与目录所属群组,这种方式采用群组名称或群组识别 码都可以.chgrp命令就是change group ...

  5. Linux 基础——权限管理命令chown、chgrp

    一.chown命令与chgrp命令的作用 有时你需要改变文件或目录的属主,比如有人离职或开发人员创建了一个在测试或生产环境中需要归属在系统账户下的应用.Linux提供了两个命令来实现这个功能:chow ...

  6. 2018/03/09 每日一个Linux命令 之 chgrp/chown

    每日一个Linux命令 2018-03-09 Linux 命令 chgrp/chown chgrp [-参数] [文件或者目录] chown [-参数] [文件所有者]:[文件所属群组] [文件或者目 ...

  7. 每天一个linux命令(25):linux文件属性详解

    Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模式.链接数量.所归属的用户和用户组.最近访问或修改的时间等内容.具体情况如下: 命令: ls -lih 输出: [root@loca ...

  8. 每天一个linux命令:chgrp

    1.命令简介         chgrp(Change group) 用来将每个指定文件的所属组设置为指定值.如果使用 --reference,则将每个文件的所属组设置为与指定参考文件相同. 2.用法 ...

  9. 【转】每天一个linux命令(25):linux文件属性详解

    原文网址:http://www.cnblogs.com/peida/archive/2012/11/23/2783762.html Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模 ...

随机推荐

  1. mysql :安装过程中的问题

    安装mysql  选择路径的问题 出现如下问题:说明之前安装过mysql,写在的不干净

  2. 自制的React同构脚手架

    代码地址如下:http://www.demodashi.com/demo/12575.html Web前端世界日新月异变化太快,为了让自己跟上节奏不掉队,总结出了自己的一套React脚手架,方便日后新 ...

  3. 有道词典for mac不能取词解决方案

    在mac上装了有道词典,发现在Chrome上不能取词,网上也没有搜到合适的解决方案,后来发现解决这个问题很简单,打开有道词典,点击设置, 再点击软件更新,就会发现有chrome取词插件,安装就OK了. ...

  4. web网页按钮如何制作

    1:用矩形形状工具画一个矩形 2 : 加描边 3:三键+N新建图层 前景色变成白色,白色到透明的渐变,选择径向渐变. 4:为了使自然,按住ALT键,使渐变扩大,和矩形保持一直,之后向上调整一些. 5: ...

  5. GitHub for window 使用教程

    Git是目前最先进的分布式版本控制系统,作为一个程序员,我们需要掌握其用法. 一:下载GitHub for Windows   二:安装GitHub  下载之后点击进行安装过程,安装之后桌面上会有两个 ...

  6. TransactionScope的用法

    using (TransactionScope ts = new TransactionScope()) { Model.user_login_log model = new Model.user_l ...

  7. The best way to predict the future is to invent it,预测未来最好的方法是创造它!

    The best way to predict the future is to invent it,预测未来最好的方法是创造它! ——Smalltalk发明人Alan Kay “预测未来的最好方法, ...

  8. Sqlserver------SQLServer2008R2中新增用户并设定表的访问权限

    在进行项目对接时,有时候处于系统安全性考虑,我们需要设置数据库的访问权限,这个时候,我们可以新增一个用户,然后设定用户的访问权限,具体步骤如下: 1,  新建登录对象 2,  点击用户映射 3,  操 ...

  9. FastDFS分布文件系统

    FastDFS是为互联网应用量身定做的一套分布式文件存储系统,非常适合用来存储用户图片.视频.文档等文件.对于互联网应用,和其他分布式文件系统相比,优势非常明显.具体情况大家可以看相关的介绍文档,包括 ...

  10. Binding基础 文摘

    简要 Binding基础 Binding源与路径 列举Binding的源 Binding基础 从Coding中看Binding的基础. 先定义一个Student类: public class Stud ...