歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 文件目錄操作命令之chgrp命令

文件目錄操作命令之chgrp命令

日期:2017/3/3 12:52:47   编辑:Linux技術

用法:chgrp [選項]... 用戶組 文件...

或:chgrp [選項]... --reference=參考文件 文件...

將每個指定文件的所屬組設置為指定值。

如果使用 --reference,則將每個文件的所屬組設置為與指定參考文件相同。

-c, --changes 類似 --verbose,但只在有更改時才顯示結果

--dereference 影響符號鏈接所指示的對象,而非符號鏈接本身(默認值)

-h, --no-dereference 會影響符號鏈接本身,而非符號鏈接所指示的目的地

(當系統支持更改符號鏈接的所有者時,此選項才有用)

--no-preserve-root 不特殊對待"/"(默認值)

--preserve-root 不允許在"/"上遞歸操作

-f, --silent, --quiet 去除大部份錯誤信息

--reference=RFILE 使用參考文件的所屬組,而非指定值

-R, --recursive 遞歸處理所有的文件及子目錄

-v, --verbose 為處理的所有文件顯示診斷信息

以下選項是在指定了 -R 選項時被用於設置如何穿越目錄結構體系。

如果您指定了多於一個選項,那麼只有最後一個會生效。

-H 如果命令行參數是一個通到目錄的符號鏈接,則遍歷符號鏈接

-L 遍歷每一個遇到的通到目錄的符號鏈接

-P 不遍歷任何符號鏈接(默認)

--help 顯示此幫助信息並退出

--version 顯示版本信息並退出

示例:

實例1:改變文件的群組屬性 (命令:chgrp-v bin test.log)

# ls -l

-rw-r--r--. 1 root root 0 5月 12 12:58 test.log

# chgrp -v bin test.log

"test.log" 的所屬組已更改為bin

# ls -l

-rw-r--r--. 1 root bin 0 5月 12 12:58 test.log

實例2:根據指定文件改變文件的群組屬性 (命令:chgrp--reference=test.log test1.log)

# ls -l

-rw-r--r--. 1 root root 0 5月 12 13:04 test1.log

-rw-r--r--. 1 root bin 0 5月 12 12:58 test.log

chgrp

--reference=test.log test1.log

#

ls -l

-rw-r--r--.

1 root bin 0 5月 12 13:04 test1.log

-rw-r--r--.

1 root bin 0 5月 12 12:58 test.log

實例3:改變指定目錄以及其子目錄下的所有文件的群組屬性(命令:chgrp -R root cmd_chgrp)# ls -l

-rw-r--r--. 1 root bin 0 5月 12 13:04 test1.log

-rw-r--r--. 1 root bin 0 5月 12 12:58 test.log

# cd ..

# chgrp -R root cmd_chgrp

# cd cmd_chgrp

# ls -l

-rw-r--r--. 1 root root 0 5月 12 13:04 test1.log

-rw-r--r--. 1 root root 0 5月 12 12:58 test.log

實例4:通過群組識別碼改變文件群組屬性(命令:chgrp -R 1 cmd_chgrp,其中1為我系統的bin群組識別碼, 具體識別碼組可以去查[b]看/etc/group文件)[/b]# ls -l

-rw-r--r--. 1 root root 0 5月 12 13:04 test1.log

-rw-r--r--. 1 root root 0 5月 12 12:58 test.log

# cd ..

# chgrp -R 1 cmd_chgrp

# cd cmd_chgrp

# ls -l

-rw-r--r--. 1 root bin 0 5月 12 13:04 test1.log

-rw-r--r--. 1 root bin 0 5月 12 12:58 test.log

Copyright © Linux教程網 All Rights Reserved