每天一個linux命令:chown


1、命令簡介

        chown(Change owner) 用來改變某個文件或目錄的所有者和所屬的組,該命令可以向某個用戶授權,使該用戶變成指定文件的所有者或者改變文件所屬的組。用戶可以是用戶或者是用戶ID,用戶組可以是組名或組ID。只有文件主和超級用戶才可以便用該命令。

2、用法

 chown [選項]... [所有者][:[組]] 文件...
 或:chown [選項]... --reference=參考文件 文件...
更改每個文件的所有者和/或所屬組。當使用 --referebce 參數時,將文件的所有者和所屬組更改為與指定參考文件相同。

3、選項

image

4、示例

示例1:將log的修改為oracle:dba
[root@oracledb dir1]# ll
總用量 0
-rw-r--r-- 1 root root 0 4月  24 15:04 log
[root@oracledb dir1]# chown oracle:dba log 
[root@oracledb dir1]# ll
總用量 0
-rw-r--r-- 1 oracle dba 0 4月  24 15:04 log
示例2:-v選項
[root@oracledb dir1]# chown -v oracle:dba log 
"log" 的所有者已保留為oracle:dba
示例3:-R遞歸修改
[root@oracledb ~]# ls -ld dir1/
drwxr-xr-x 2 root root 4096 4月  24 15:04 dir1/
[root@oracledb ~]# chown -Rv oracle:dba dir1
"dir1/log" 的所有者已保留為oracle:dba
"dir1" 的所有者已更改為oracle:dba
實例4:所屬組若沒有指定不會更改,但當加上":"時 GROUP 會更改為指定所有者的主要組。
[root@oracledb dir1]# chown -v oracle:  log 
"log" 的所有者已更改為oracle:oinstall
實例5:如果沒有指定所有者,只指定組
[root@oracledb dir1]# chown -v :dba  log 
"log" 的所有者已更改為:dba
實例6:所有者和所屬組可以是ID
[root@oracledb dir1]# chown -v 0:0  log 
"log" 的所有者已更改為0:0
[root@oracledb dir1]# ll
總用量 0
-rw-r--r-- 1 root root 0 4月  24 15:04 log
實例7:將log2的所有者和所屬組改為和log1一樣
[root@oracledb dir1]# ll
總用量 0
-rw-r--r-- 1 oracle dba  0 4月  24 15:04 log1
-rw-r--r-- 1 root   root 0 4月  25 20:27 log2

[root@oracledb dir1]# chown --reference=log2  log1
[root@oracledb dir1]# ll
總用量 0
-rw-r--r-- 1 root root 0 4月  24 15:04 log1
-rw-r--r-- 1 root root 0 4月  25 20:27 log2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM