系統(tǒng)之家 - 系統(tǒng)光盤下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > Linux使用chgrp命令的方法

Linux使用chgrp命令修改文件所屬群組的方法

時間:2014-12-30 16:29:42 作者:qipeng 來源:系統(tǒng)之家 1. 掃描二維碼隨時看資訊 2. 請使用手機瀏覽器訪問: https://m.xitongzhijia.net/xtjc/20141230/33754.html 手機查看 評論

  使用Linux系統(tǒng)中的chgrp命令可以修改文件或目錄的所屬群組,那么chgrp命令還有哪些用法呢?下面系統(tǒng)之家的小編就給大家詳細介紹下Linux chgrp命令的用法,有興趣的朋友不妨來了解下。

 Linux使用chgrp命令修改文件所屬群組的方法

  Chgrp命令就是change group的縮寫!要被改變的組名必須要在/etc/group文件內(nèi)存在才行。

  1.命令格式:

  chgrp [選項] [組] [文件]

  2.命令功能:

  chgrp命令可采用群組名稱或群組識別碼的方式改變文件或目錄的所屬群組。使用權(quán)限是超級用戶。

  3.命令參數(shù):

  必要參數(shù):

  -c 當(dāng)發(fā)生改變時輸出調(diào)試信息

  -f 不顯示錯誤信息

  -R 處理指定目錄以及其子目錄下的所有文件

  -v 運行時顯示詳細的處理信息

  --dereference 作用于符號鏈接的指向,而不是符號鏈接本身

  --no-dereference 作用于符號鏈接本身

  選擇參數(shù):

  --reference=《文件或者目錄》

  --help 顯示幫助信息

  --version 顯示版本信息

  4.使用實例:

  實例1:改變文件的群組屬性

  命令:

  代碼如下:

  chgrp -v bin log2012.log

  輸出:

  代碼如下:

 。踨oot@localhost test]# ll

  ---xrw-r-- 1 root root 302108 11-13 06:03 log2012.log

  [root@localhost test]# chgrp -v bin log2012.log

  “log2012.log” 的所屬組已更改為 bin

 。踨oot@localhost test]# ll

  ---xrw-r-- 1 root bin 302108 11-13 06:03 log2012.log

  說明:

  將log2012.log文件由root群組改為bin群組

  實例2:根據(jù)指定文件改變文件的群組屬性

  命令:

  代碼如下:

  chgrp --reference=log2012.log log2013.log

  輸出:

  代碼如下:

 。踨oot@localhost test]# ll

  ---xrw-r-- 1 root bin 302108 11-13 06:03 log2012.log

  -rw-r--r-- 1 root root 61 11-13 06:03 log2013.log

  [root@localhost test]# chgrp --reference=log2012.log log2013.log

 。踨oot@localhost test]# ll

  ---xrw-r-- 1 root bin 302108 11-13 06:03 log2012.log

  -rw-r--r-- 1 root bin 61 11-13 06:03 log2013.log

  說明:

  改變文件log2013.log 的群組屬性,使得文件log2013.log的群組屬性和參考文件log2012.log的群組屬性相同

  實例3:改變指定目錄以及其子目錄下的所有文件的群組屬性

  命令:

  代碼如下:

  chgrp -R bin test6

  輸出:

  代碼如下:

 。踨oot@localhost test]# ll

  drwxr-xr-x 2 root root 4096 11-30 08:39 test6

 。踨oot@localhost test]# cd test6

  [root@localhost test6]# ll

  ---xr--r-- 1 root root 302108 11-30 08:39 linklog.log

  ---xr--r-- 1 root root 302108 11-30 08:39 log2012.log

  -rw-r--r-- 1 root root 61 11-30 08:39 log2013.log

  -rw-r--r-- 1 root root 0 11-30 08:39 log2014.log

  -rw-r--r-- 1 root root 0 11-30 08:39 log2015.log

  -rw-r--r-- 1 root root 0 11-30 08:39 log2016.log

  -rw-r--r-- 1 root root 0 11-30 08:39 log2017.log

 。踨oot@localhost test6]# cd 。。

 。踨oot@localhost test]# chgrp -R bin test6

  [root@localhost test]# cd test6

 。踨oot@localhost test6]# ll

  ---xr--r-- 1 root bin 302108 11-30 08:39 linklog.log

  ---xr--r-- 1 root bin 302108 11-30 08:39 log2012.log

  -rw-r--r-- 1 root bin 61 11-30 08:39 log2013.log

  -rw-r--r-- 1 root bin 0 11-30 08:39 log2014.log

  -rw-r--r-- 1 root bin 0 11-30 08:39 log2015.log

  -rw-r--r-- 1 root bin 0 11-30 08:39 log2016.log

  -rw-r--r-- 1 root bin 0 11-30 08:39 log2017.log

  [root@localhost test6]# cd 。。

 。踨oot@localhost test]# ll

  drwxr-xr-x 2 root bin 4096 11-30 08:39 test6

  [root@localhost test]#《/p》 《p》

  說明:

  改變指定目錄以及其子目錄下的所有文件的群組屬性

  實例4:通過群組識別碼改變文件群組屬性

  命令:

  代碼如下:

  chgrp -R 100 test6

  輸出:

  代碼如下:

 。踨oot@localhost test]# chgrp -R 100 test6

  [root@localhost test]# ll

  drwxr-xr-x 2 root users 4096 11-30 08:39 test6

 。踨oot@localhost test]# cd test6

 。踨oot@localhost test6]# ll

  ---xr--r-- 1 root users 302108 11-30 08:39 linklog.log

  ---xr--r-- 1 root users 302108 11-30 08:39 log2012.log

  -rw-r--r-- 1 root users 61 11-30 08:39 log2013.log

  -rw-r--r-- 1 root users 0 11-30 08:39 log2014.log

  -rw-r--r-- 1 root users 0 11-30 08:39 log2015.log

  -rw-r--r-- 1 root users 0 11-30 08:39 log2016.log

  -rw-r--r-- 1 root users 0 11-30 08:39 log2017.log

  [root@localhost test6]#

  說明:

  通過群組識別碼改變文件群組屬性,100為users群組的識別碼,具體群組和群組識別碼可以去/etc/group文件中查看

  上面就是Linux種chgrp命令的用法介紹了,需要特別注意的是,chgrp命令修改文件所屬群組是有權(quán)限限制的,只有超級用戶才有資格修改,普通用戶無法使用。

發(fā)表評論

0

沒有更多評論了

評論就這些咯,讓大家也知道你的獨特見解

立即評論

以上留言僅代表用戶個人觀點,不代表系統(tǒng)之家立場

其他版本軟件

熱門教程

人氣教程排行

Linux系統(tǒng)推薦

官方交流群 軟件收錄