Linux chown命令詳細(xì)介紹和使用實(shí)例(改變文件或目錄的所有者)
發(fā)布日期:2022-03-15 19:43 | 文章來(lái)源:站長(zhǎng)之家
系統(tǒng)管理員經(jīng)常使用chown命令,在將文件拷貝到另一個(gè)用戶的名錄下之后,讓用戶擁有使用該文件的權(quán)限。
1.命令格式:
復(fù)制代碼
代碼如下:chown [選項(xiàng)]... [所有者][:[組]] 文件...
2.命令功能:
通過(guò)chown改變文件的擁有者和群組。在更改文件的所有者或所屬群組時(shí),可以使用用戶名稱和用戶識(shí)別碼設(shè)置。普通用戶不能將自己的文件改變成其他的擁有者。其操作權(quán)限一般為管理員。
3.命令參數(shù):
必要參數(shù):
-c 顯示更改的部分的信息
-f 忽略錯(cuò)誤信息
-h 修復(fù)符號(hào)鏈接
-R 處理指定目錄以及其子目錄下的所有文件
-v 顯示詳細(xì)的處理信息
-deference 作用于符號(hào)鏈接的指向,而不是鏈接文件本身
選擇參數(shù):
--reference=<目錄或文件> 把指定的目錄/文件作為參考,把操作的文件/目錄設(shè)置成參考文件/目錄相同擁有者和群組
--from=<當(dāng)前用戶:當(dāng)前群組> 只有當(dāng)前用戶和群組跟指定的用戶和群組相同時(shí)才進(jìn)行改變
--help 顯示幫助信息
--version 顯示版本信息
4.使用實(shí)例:
實(shí)例1:改變擁有者和群組
命令:
復(fù)制代碼
代碼如下:chown mail:mail log2012.log
輸出:
復(fù)制代碼
代碼如下:[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 users0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users0 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 users0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users0 11-30 08:39 log2017.log
[root@localhost test6]#
---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 users0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users0 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 users0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users0 11-30 08:39 log2017.log
[root@localhost test6]#
說(shuō)明:
實(shí)例2:改變文件擁有者和群組
命令:
復(fù)制代碼
代碼如下:chown root: log2012.log
輸出:
復(fù)制代碼
代碼如下:[root@localhost test6]# ll
總計(jì) 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 users0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users0 11-30 08:39 log2017.log
[root@localhost test6]# chown root: log2012.log
[root@localhost test6]# ll
總計(jì) 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 users0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users0 11-30 08:39 log2017.log
[root@localhost test6]#
說(shuō)明:
實(shí)例3:改變文件群組
命令:
復(fù)制代碼
代碼如下:chown :mail log2012.log
輸出:
復(fù)制代碼
代碼如下:[root@localhost test6]# ll
總計(jì) 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 users0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users0 11-30 08:39 log2017.log
[root@localhost test6]# chown :mail log2012.log
[root@localhost test6]# ll
總計(jì) 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 users0 11-30 08:39 log2014.log
-rw-r--r-- 1 root users0 11-30 08:39 log2015.log
-rw-r--r-- 1 root users0 11-30 08:39 log2016.log
-rw-r--r-- 1 root users0 11-30 08:39 log2017.log
說(shuō)明:
實(shí)例4:改變指定目錄以及其子目錄下的所有文件的擁有者和群組
命令:
復(fù)制代碼
代碼如下:chown -R -v root:mail test6
輸出:
復(fù)制代碼
代碼如下:[root@localhost test]# ll
drwxr-xr-x 2 root users4096 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 mail4096 11-30 08:39 test6
[root@localhost test]# cd test6
[root@localhost test6]# ll
總計(jì) 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 mail0 11-30 08:39 log2014.log
-rw-r--r-- 1 root mail0 11-30 08:39 log2015.log
-rw-r--r-- 1 root mail0 11-30 08:39 log2016.log
-rw-r--r-- 1 root mail0 11-30 08:39 log2017.log
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章
關(guān)注官方微信