來源:
http://www.cnblogs.com/peida/archive/2012/12/04/2800684.html
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]# ll
drwxr-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]# ll
drwxr-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