linux關於檔案分配置許可權

來源:互聯網
上載者:User

指令名稱 : chown 使用許可權 : root

使用方式 : chown [-cfhvR] [--help] [--version] user[:group] file…

PS : 利用 chown 可以將檔案的擁有者加以改變。這個指令只有是由系統管理者(root)所使用,一般使用者沒有許可權可以改變別人的檔案擁有者,也沒有許可權可以自己的檔案擁有者改設為別人。

參數:
-c或-change:作用與-v相似,但只傳回修改的部分
-f或–quiet或–silent:不顯示錯誤資訊
-h或–no-dereference:只對符號連結的檔案做修改,而不更改其他任何相關檔案
-R或-recursive:遞迴處理,將指定目錄下的所有檔案及子目錄一併處理
-v或–verbose:顯示指令執行過程
–dereference:作用和-h剛好相反
–help:顯示線上說明
–reference=<參考檔案或目錄>:把指定檔案或目錄的所有者與所屬組,統統設定成和參考檔案或目錄的所有者與所屬組相同
–version:顯示版本資訊

chown命令使用舉例:

# chown [-R] [使用者名稱稱] [檔案或目錄]
# chown[-R] [使用者名稱稱:組名稱] [檔案或目錄]

範例1:將test3.txt檔案的屬主改為test使用者。
# ls -l test3.txt
-rw-r–r– 1 test root 0 2009-10-23 9:59 test3.txt
# chown test:root test3.txt
# ls -l test3.txt
-rw-r–r– 1 test root 0 2009-10-23 9:59

範例2:chown所接的新的屬主和新的屬組之間可以使用:串連,屬主和屬組之一可以為空白。如果屬主為空白,應該是“:屬組”;如果屬組為空白,“:”可以不用帶上。

# ls -l test3.txt
-rw-r–r– 1 test root 0 2009-10-23 9:59 test3.txt

# chown :test test3.txt <==把檔案test3.txt的屬組改為test
# ls -l test3.txt
-rw-r–r– 1 test test 0 2009-10-23 9:59 test3.txt

範例3:chown也提供了-R參數,這個參數對目錄改變屬主和屬組極為有用,可以通過加 -R參數來改變某個目錄下的所有檔案到新的屬主或屬組。
# ls -l testdir <== 查看testdir目錄屬性
drwxr-xr-x 2 usr root 0 2009-10-56 10:38 testdir/ <==檔案屬主是usr使用者,屬組是 root使用者
# ls -lr testdir <==查看testdir目錄下所有檔案及其屬性
total 0
-rw-r–r– 1 usr root 0 2009-10-23 10:38 test1.txt
-rw-r–r– 1 usr root 0 2009-10-23 10:38 test2.txt
-rw-r–r– 1 usr root 0 2009-10-23 10:38 test3.txt
# chown -R test:test testdir/ <==修改testdir及它的下級目錄和所有檔案到新的使用者和使用者組
# ls -l testdir
drwxr-xr-x 2 test test 0 2009-10-23 10:38 testdir/
# ls -lr testdir
total 0
-rw-r–r– 1 test test 0 2009-10-23 10:38 test1.txt
-rw-r–r– 1 test test 0 2009-10-23 10:38 test2.txt
-rw-r–r– 1 test test 0 2009-10-23 10:38 test3.txt

總之,我這裡的用法就很簡單,chown oracle /rmanbk/logs就可以了…什麼使用者組和我都沒關係了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.