Linux常用命令 二十三 chgrp

2021-06-27 06:58:32 字數 3296 閱讀 8252

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

1.命令格式:

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

2.命令功能:

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

3.命令引數:

必要引數:

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

-f 不顯示錯誤資訊

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

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

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

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

選擇引數:

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

--help 顯示幫助資訊

--version 顯示版本資訊

4.命令例項:

例項一.改變檔案的群組屬性

命令: chgrp -v bin log2012.log

說明: 將log2012.log檔案由root群組改為bin群組

[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

例項二.根據指定檔案改變檔案的群組屬性

命令: chgrp --reference=log2012.log log2013.log

說明: 改變檔案log2013.log的群組屬性, 使檔案log2013.log的群組屬性和參考檔案log2012.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

例項三. 改變指定目錄及其子目錄的所有檔案的群組屬性

命令: chgrp -r bin test6

說明: 改變test6目錄及其子目錄所有群組屬性為bin

[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

[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

[root@localhost test6]# cd ..

[root@localhost test]# ll

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

[root@localhost test]#

例項四. 通過群組識別碼改變檔案群組屬性

命令: chgrp -r 100 test6

說明: 100為users群組的識別碼, 具體群組和群組識別碼可以去/etc/group檔案中檢視

[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

[root@localhost test6]#

Linux常用命令 二十

linux中的分割槽格式化 前面我們已經說過了磁碟分割槽的兩種方法,現在就要對分好區的磁碟進行格式化 ls l dev sda 檢視當前的磁碟分割槽情況 mkfs.ext3 dev sdb1 格式化檔案,把檔案系統型別指定為ext3 mkfs t ext4 dev sdb2 第二種格式化命令,把 d...

linux系列(二十三) df命令

1 命令格式 df 選項 檔案 2 命令功能 顯示指定磁碟檔案的可用空間。如果沒有檔名被指定,則所有當前被掛載的檔案系統的可用空間將被顯示。預設情況下,磁碟空間將以 1kb 為單位進行顯示,除非環境變數 posixly correct 被指定,那樣將以512位元組為單位進行顯示 3 命令引數 必要引...

Linux基礎(二十三)

進入linux字元介面方式有字元介面 圖形介面下的終端以及虛擬控制台等方式。在字元介面下,虛擬控制台的選擇可以通過按下 alt 鍵和1個功能鍵來實現,功能鍵通常為f1 f6鍵。比如使用者登入後,按下 alt f2 鍵,使用者可以看 login 提示符,說明使用者進入了第2個虛擬控制台。然後只需利用按...