1. 程式人生 > >Linux基礎命令---chgrp

Linux基礎命令---chgrp

chgrp

改變檔案或者目錄所屬的群組,使用引數“--reference”,可以改變檔案的群組為指定的關聯檔案群組。此命令的適用範圍:RedHat、RHEL、Ubuntu、CentOS、SUSE、openSUSE、Fedora。

 

1、語法

chgrp [選項]  group  file

chgrp [選項]  –reference=RFILE  file

 

2、選項列表

選項

說明

--version

顯示命令版本資訊

--help

顯示幫助文件

-c | --changes

和verbose一樣,但是隻有在發生改變的時候才顯示詳細資訊

--dereference

改變符號連結所指向的檔案,而不是符號連結自己。這是預設選項

-h | --no-dereference

修改符號連結,僅適用於可更改符號連結所有權的系統

--no-preserve-root

不要特殊處理“/”,預設選項

--preserve-root

未能對“/”進行遞迴操作

-f | --silent | --quiet

忽略部分錯誤資訊

--reference=file

使用關聯檔案所屬的組,而不是指出一個具體的值

-R, --recursive

遞迴處理目錄及其內部的檔案

-v | --verbose

顯示詳細資訊

-H

如果命令列引數是指向目錄的符號連結,請遍歷它。配合”-R”使用

-L

遍歷到遇到的目錄的每個符號連結。配合”-R”使用

-P

不要遍歷任何符號連結(預設)。配合”-R”使用

 

3、例項-

1)修改檔案所屬的組

[[email protected] weijie]# ls l                   //使用ls檢視詳細資訊

總用量 1072

-rw-r--r-- 1 root root      0 9   7 09:11 1.c

-rw-r--r-- 3 root root 358400 9   7 15:46 link

 [[email protected] weijie]# chgrp weijie 1.c    //修改組

[[email protected] weijie]# ls l                  //再次檢視,修改已經成功

總用量 1072

-rw-r--r-- 1 root weijie      0 9  7 09:11 1.c

-rw-r--r-- 3 root root   358400 9   7 15:46 link

2)使用選項“--reference”

[[email protected] weijie]# chgrp --reference=1.c my.iso         //1.c的組已經是weijie

[[email protected] weijie]# ls -l

總用量 1072

-rw-r--r-- 1 root weijie      0 9   7 09:11 1.c

-rw-r--r-- 3 root weijie 358400 9   7 15:46 my.iso           //my.iso所屬的組也變成wiejie

3)只修改符號連結自己

[[email protected] wj]# ls -l 1.c 11.c                               //檢視檔案資訊

lrwxrwxrwx 1 root root 3 10 26 10:11 11.c -> 1.c

-rw-r--r-- 1 root root 0 10 24 10:12 1.c

[[email protected] wj]# chgrp -h weijie 11.c                       //修改組

[[email protected] wj]# ls -l 1.c 11.c                              //檢視檔案資訊,只有符號連結自己的組被修改了

lrwxrwxrwx 1 root weijie 3 10 26 10:11 11.c -> 1.c

-rw-r--r-- 1 root root   0 10 24 10:12 1.c