更改linux檔案的擁有者及使用者組(chown和chgrp)

來源:互聯網
上載者:User

標籤:linux

、使用 chown命令變更檔擁有者在 shell 中,可以使用chown命令來改變檔案所有者。chown命令是change owner(改變擁有者)的縮寫。需要要注意的是,使用者必須是已經存在系統中的,也就是只能改變為在 /etc/passwd這個檔案中有記錄的使用者名稱稱才可以。chown命令的用途很多,還可以順便直接修改使用者組的名稱。此外,如果要連目錄下的所有子目錄或檔案同時變更檔擁有者的話,直接加上 -R的參數即可。 基本文法:chown [-R] 帳號名稱 檔案或目錄chown [-R] 帳號名稱:使用者組名稱 檔案或目錄 參數:-R : 進行遞迴( recursive )的持續更改,即連同子目錄下的所有檔案、目錄都更新成為這個使用者組。常常用在更改某一目錄的情況。 樣本1:[[email protected] home]# touch testfile //由 root 使用者建立檔案 [[email protected] home]# ls testfile –l -rw--w--w- 1 root root 0 Jun 7 19:35 testfile //檔案的擁有者及擁有者級均為 root [[email protected] home]# chown yangzongde testfile //修改檔案擁有者為 yangzongde [[email protected] home]# ls testfile -l -rw--w--w- 1 yangzongde root 0 Jun 7 19:35 testfile //查看檔案擁有者為 yangzongde,但組仍為 root  樣本2:chown bin install.logls -l-rw-r--r--  1 bin  users 68495 Jun 25 08:53 install.logchown root:root install.logls -l-rw-r--r--  1 root root 68495 Jun 25 08:53 install.log三、使用 chgrp命令變更檔所屬使用者組在shell中,可以使用chgrp命令來改變檔案所屬使用者組,該命令就是change group(改變使用者組)的縮寫。需要注意的是要改變成為的使用者組名稱,必須在 /etc/group裡存在,否則就會顯示錯誤。基本文法:chgrp [-R] 使用者組名稱 dirname/filename ... 參數:-R : 進行遞迴( recursive )的持續更改,即連同子目錄下的所有檔案、目錄都更新成為這個使用者組。常常用在更改某一目錄的情況。 樣本3[[email protected] home]# ls testfile -l -rw--w--w- 1 yangzongde root 0 Jun 7 19:35 testfile //查看檔案擁有者為 yangzongde,但組為 root [[email protected] home]# chgrp yangzongde testfile //修改擁有者組為 yangzongde [[email protected] home]# ls testfile -l -rw--w--w- 1 yangzongde yangzongde 0 Jun 7 19:35 testfile [[email protected] home]# chown root:root testfile // 使用 chown 一次性修改擁有者及組 [[email protected] home]# ls testfile -l -rw--w--w- 1 root root 0 Jun 7 19:35 testfile  樣本4[[email protected] ~]# chgrp users install.log[[email protected] ~]# ls -l-rw-r--r--  1 root users 68495 Jun 25 08:53 install.log 樣本5更改為一個 /etc/group裡不存在的使用者組[[email protected] ~]# chgrp testing install.logchgrp: invalid group name `testing‘ <== 出現錯誤資訊~找不到這個使用者組名~

更改linux檔案的擁有者及使用者組(chown和chgrp)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.