Linux如何用命令管理文件和目錄的權限

Linux如何用命令管理文件和目錄的權限?針對這個問題,今天小編總結這篇有關linux文件和目錄權限的文章,可供感興趣的小伙伴們參考借鑒,希望對大家有所幫助。

創(chuàng)新互聯(lián)建站堅信:善待客戶,將會成為終身客戶。我們能堅持多年,是因為我們一直可值得信賴。我們從不忽悠初訪客戶,我們用心做好本職工作,不忘初心,方得始終。10余年網(wǎng)站建設經(jīng)驗創(chuàng)新互聯(lián)建站是成都老牌網(wǎng)站營銷服務商,為您提供成都網(wǎng)站設計、成都網(wǎng)站制作、網(wǎng)站設計、H5網(wǎng)站設計、網(wǎng)站制作、品牌網(wǎng)站制作、小程序制作服務,給眾多知名企業(yè)提供過好品質的建站服務。

一、文件的權限和歸屬概述

1、訪問權限

  • 讀取r:允許查看文件內(nèi)容、顯示目錄列表;

  • 寫入w:允許修改文件內(nèi)容,允許在目錄中新建、移動、刪除文件或子目錄;

  • 可執(zhí)行x:允許運行程序、切換目錄

2、歸屬(所有權)

  • 屬主:擁有該文件或目錄的用戶賬號;

  • 屬組:擁有該文件或目錄的組賬號;

3、查看文件的權限和歸屬

Linux如何用命令管理文件和目錄的權限

4、chmod設置文件權限

chmod命令的基本語法格式如下:
Linux如何用命令管理文件和目錄的權限

應用舉例:

[root@centos01 ~]# touch 1.txt     <!--創(chuàng)建1.txt文件-->
[root@centos01 ~]# ll 
總用量 8
-rw-r--r--  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u+x ./1.txt  <!--屬主用戶添加執(zhí)行權限-->
[root@centos01 ~]# ll
總用量 8
-rwxr--r--  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u-x,g+x,o+w 1.txt   
<!--屬主用戶取消執(zhí)行權限,組添加執(zhí)行權限,其他用戶添加寫入權限-->
[root@centos01 ~]# ll
總用量 8
-rw-r-xrw-  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod 755 1.txt  <!--添加755權限(rwxr-xr-x)-->
[root@centos01 ~]# ll
總用量 8
-rwxr-xr-x  1 root root    0 1月  17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

5、chown設置文件的歸屬

chown命令的基本語法格式如下:
Linux如何用命令管理文件和目錄的權限

應用舉例:

[root@centos01 ~]# chown bob 1.txt  <!--1.txt設置屬主-->
[root@centos01 ~]# ll
總用量 8
-rwxr-xr-x  1 bob  root    0 1月  17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown :benet 1.txt  <!--1.txt設置屬組-->
[root@centos01 ~]# ll
總用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 02:36 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown bob:benet 1.txt  <!--1.txt設置屬主和屬組-->
[root@centos01 ~]# ll
總用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 02:36 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg
<!---->

二、目錄的權限和歸屬

1、訪問權限

Linux如何用命令管理文件和目錄的權限

2、歸屬(所有權)

  • 屬主:擁有該目錄的用戶賬號;

  • 屬組:擁有該目錄的組賬號;

3、chmod設置目錄權限

chmod命令設置目錄權限的基本格式如下:
Linux如何用命令管理文件和目錄的權限

應用舉例:

[root@centos01 ~]# chmod -R 755 benet/   
          <!--循環(huán)設置benet目錄下的文件或者目錄權限為755-->
[root@centos01 ~]# ll
總用量 8
-rw-r-xrw-  1 root root    0 1月  11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
drwxr-xr-x  3 root root   18 1月  11 22:39 benet
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

4、chown設置目錄的歸屬

chown命令設置目錄歸屬的基本格式如下:
Linux如何用命令管理文件和目錄的權限

應用舉例:

[root@centos01 ~]# chown -R bob:benet benet/   
   <!--循環(huán)設置benet目錄中所屬用戶為bob,所屬組為benet-->
[root@centos01 ~]# ll
總用量 8
-rw-r-xrw-  1 root root     0 1月  11 22:27 1.txt
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
drwxr-xr-x  3 bob  benet   18 1月  11 22:39 benet
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg

三、權限掩碼umask

1、umask的作用

控制新建的文件或目錄的權限,默認權限去除umask的權限就是新建的文件或者目錄的權限。

2、設置umask

umask 022

3、查看umask

umask

4、應用舉例:

[root@centos01 ~]# umask  <!--查看umask-->
0022
[root@centos01 ~]# umask 000  <!--設置umask為000-->
[root@centos01 ~]# umask   <!--驗證是否設置成功-->
0000
[root@centos01 ~]# touch 2.txt   <!--創(chuàng)建新文件-->
[root@centos01 ~]# ll
總用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 03:48 1.txt
-rw-rw-rw-  1 root root     0 1月  17 03:48 2.txt    <!--查看權限-->
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# umask 022       <!--設置umask為022-->
[root@centos01 ~]# umask           <!--查看umask-->
0022
[root@centos01 ~]# touch 3.txt        <!--再次創(chuàng)建新文件-->
[root@centos01 ~]# ll
總用量 8
-rwxr-xr-x  1 bob  benet    0 1月  17 03:48 1.txt
-rw-rw-rw-  1 root root     0 1月  17 03:48 2.txt
-rw-r--r--  1 root root     0 1月  17 03:49 3.txt <!--查看權限,明顯不一樣-->
-rw-------. 1 root root  1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root  1603 10月 23 23:36 initial-setup-ks.cfg

看完這篇文章,你們學會管理文件和目錄的權限的方法了嗎?如果還想學到更多技能或想了解更多相關內(nèi)容,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀。

文章名稱:Linux如何用命令管理文件和目錄的權限
鏈接URL:http://bm7419.com/article32/jdcepc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)全網(wǎng)營銷推廣、外貿(mào)網(wǎng)站建設、響應式網(wǎng)站、動態(tài)網(wǎng)站、搜索引擎優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化