每天乙個linux命令(28) chgrp命令

2021-08-21 10:43:40 字數 4579 閱讀 3566

在lunix系統裡,檔案或目錄的許可權的掌控以擁有者及所訴群組來管理。可以使用chgrp指令取變更檔案與目錄所屬群組,這種方式採用群組名稱或群組識別碼都可以。chgrp命令就是change group的縮寫!要被改變的組名必須要在/etc/group檔案內存在才行。

1.命令格式:

chgrp [選項] [組] [檔案]

2.命令功能:

chgrp命令可採用群組名稱或群組識別碼的方式改變檔案或目錄的所屬群組。使用許可權是超級使用者。

3.命令引數:

必要引數:

-c 當發生改變時輸出除錯資訊

-f 不顯示錯誤資訊

-r 處理指定目錄以及其子目錄下的所有檔案

-v 執行時顯示詳細的處理資訊

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

--no-dereference 作用於符號鏈結本身

選擇引數:

--reference=《檔案或者目錄》

--help 顯示幫助資訊

--version 顯示版本資訊

4.使用例項:

例項1:改變檔案的群組屬性

命令:

chgrp -v bin log2012.log

輸出:

[root@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

[root

@localhost test]#ll

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

說明:

將log2012.log

檔案由root群組改為bin群組

例項2:根據指定檔案改變檔案的群組屬性

命令:

chgrp --reference=log2012.log log2013.log

輸出:

[root@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 

[root@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:改變指定目錄以及其子目錄下的所有檔案的群組屬性

命令:

輸出:

[root@localhost test]#ll

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

test6

[root

@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

[root

@localhost test6]

#cd ..

[root@localhost test]

#chgrp -r bin test6

[root@localhost test]

#cd test6

[root@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 ..

[root@localhost test]#ll

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

test6

[root

@localhost test]

#說明:

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

例項4:通過群組識別碼改變檔案群組屬性

命令:

chgrp -r 100 test6

輸出:

[root@localhost test]

#chgrp -r 100 test6

[root@localhost test]#ll

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

test6

[root

@localhost test]

#cd test6

[root@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命令 28 gzip命令

減少檔案大小有兩個明顯的好處,一是可以減少儲存空間,二是通過網路傳輸檔案時,可以減少傳輸的時間。gzip 是在linux 系統中經常使用的乙個對檔案進行壓縮和解壓縮的命令,既方便又好用。gzip 不僅可以用來壓縮大的 較少使用的檔案以節省磁碟空間,還可以和tar 命令一起構成linux 作業系統中比...

每天乙個Linux命令

將我遇到的linux指令總結一下,不斷增加 1 sz和rz 一般來說,linux 伺服器大多是通過 ssh客戶端來進行遠端的登陸和管理的,使用 ssh登陸 linux ssh有關的兩個命令可以提供很方便的操作 sz 將選定的檔案傳送 send 到本地機器 rz 執行該命令會彈出乙個檔案選擇視窗,從本...

每天乙個linux命令

linux cmp命令 linux cmp命令用於比較兩個檔案是否有差異。當相互比較的兩個檔案完全一樣時,則該指令不會顯示任何資訊。若發現有所差異,缺省會標示出第乙個不同之處的字元和列數編號。若不指定任何檔名稱或是所給予的檔名為 則cmp指令會從標準輸入裝置讀取資料。語法cmp clsv i 字元數...