chown將指定檔案的擁有者改為指定的使用者或組,使用者可以是使用者名稱或者使用者ID;組可以是組名或者組ID;檔案是以空格分開的要改變許可權的檔案清單,支援萬用字元。系統管理員經常使用chown命令,在將檔案拷貝到另一個使用者的名錄下之後,讓使用者擁有使用該檔案的許可權。
1.命令格式:
chown [選項]... [所有者][:[組]] 檔案...
2.命令功能:
通過chown改變檔案的擁有者和群組。在變更檔的所有者或所屬群組時,可以使用使用者名稱稱和使用者識別碼設定。普通使用者不能將自己的檔案改變成其他的擁有者。其操作許可權一般為管理員。
3.命令參數:
必要參數:
-c 顯示更改的部分的資訊
-f 忽略錯誤資訊
-h 修複符號連結
-R 處理指定目錄以及其子目錄下的所有檔案
-v 顯示詳細的處理資訊
-deference 作用於符號連結的指向,而不是連結檔案本身
選擇參數:
--reference=<目錄或檔案> 把指定的目錄/檔案作為參考,把操作的檔案/目錄設定成參考檔案/目錄相同擁有者和群組
--from=<目前使用者:當前群組> 只有目前使用者和群組跟指定的使用者和群組相同時才進行改變
--help 顯示協助資訊
--version 顯示版本資訊
4.使用執行個體:
執行個體1:改變擁有者和群組
命令:
chown mail:mail log2012.log
輸出:
[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]# chown mail:mail log2012.log [root@localhost test6]# ll---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 mail mail 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]#
說明:
執行個體2:改變檔案擁有者和群組
命令:
chown root: log2012.log
輸出:
[root@localhost test6]# ll總計 604---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 mail mail 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]# chown root: log2012.log [root@localhost test6]# ll總計 604---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 root root 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]#
說明:
執行個體3:改變檔案群組
命令:
chown :mail log2012.log
輸出:
[root@localhost test6]# ll總計 604---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 root root 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]# chown :mail log2012.log [root@localhost test6]# ll總計 604---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 root mail 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
說明:
執行個體4:改變指定目錄以及其子目錄下的所有檔案的擁有者和群組
命令:
chown -R -v root:mail test6
輸出:
[root@localhost test]# lldrwxr-xr-x 2 root users 4096 11-30 08:39 test6[root@localhost test]# chown -R -v root:mail test6“test6/log2014.log” 的所有者已更改為 root:mail“test6/linklog.log” 的所有者已更改為 root:mail“test6/log2015.log” 的所有者已更改為 root:mail“test6/log2013.log” 的所有者已更改為 root:mail“test6/log2012.log” 的所有者已保留為 root:mail“test6/log2017.log” 的所有者已更改為 root:mail“test6/log2016.log” 的所有者已更改為 root:mail“test6” 的所有者已更改為 root:mail[root@localhost test]# lldrwxr-xr-x 2 root mail 4096 11-30 08:39 test6[root@localhost test]# cd test6[root@localhost test6]# ll總計 604---xr--r-- 1 root mail 302108 11-30 08:39 linklog.log---xr--r-- 1 root mail 302108 11-30 08:39 log2012.log-rw-r--r-- 1 root mail 61 11-30 08:39 log2013.log-rw-r--r-- 1 root mail 0 11-30 08:39 log2014.log-rw-r--r-- 1 root mail 0 11-30 08:39 log2015.log-rw-r--r-- 1 root mail 0 11-30 08:39 log2016.log-rw-r--r-- 1 root mail 0 11-30 08:39 log2017.log
說明: