Linux之档案管理

1:档案类型[1]

  d :目录

  -:档案

  l:链接档

  b:装置文件中可存储接口设备

  c:装置文件中串行设备,例如:键盘,鼠标

2:RWX:

  R:read (可读),W:write(可写),X:excute(可执行)

注意:如果文件为目录,无X权限,不可访问目录。

3:改变档案权限

  chown:改变档案的拥有者

  chgrp:改变档案的所属群组

  chmod:改变档案的属性,SUID等

chmod的设置分两种:数字和字符

r:4

w:2
x:1

每3位一组

user :u

group:g

outhers:o

a代表u,g,o 所有

符号:+,-,=

说明:+和-:在原权限基础上增减,=:直接设置目标权限

chown:

  

1 [root@zkero ~]# touch test
2 [root@zkero ~]# ll test
3 -rw-r--r-- 1 root root 0 Jun 17 23:04 test
4 [root@zkero ~]# chown supker test
5 [root@zkero ~]# ll test
6 -rw-r--r-- 1 supker root 0 Jun 17 23:04 test

chgrp:

1 [root@zkero ~]# chgrp supker test
2 [root@zkero ~]# ll test
3 -rw-r--r-- 1 supker supker 0 Jun 17 23:04 test

chmod:

 

1 [root@zkero ~]# ll test
2 -rw-r--r-- 1 supker supker 0 Jun 17 23:04 test
3 [root@zkero ~]# chmod 777 test
4 [root@zkero ~]# ll test
5 -rwxrwxrwx 1 supker supker 0 Jun 17 23:04 test
1 [root@zkero ~]# ll test
2 -rwxrwxrwx 1 supker supker 0 Jun 17 23:04 test
3 [root@zkero ~]# chmod g=rw,o=- test
4 [root@zkero ~]# ll test
5 -rwxrw---- 1 supker supker 0 Jun 17 23:04 test
6 [root@zkero ~]# 

其中o=-,可以写成o=           

 1 1 [root@zkero ~]# ll test
 2 2 -rw-rw---- 1 supker supker 0 Jun 17 23:04 test
 3 3 [root@zkero ~]# chmod a+x test
 4 4 [root@zkero ~]# ll test
 5 5 -rwxrwx--x 1 supker supker 0 Jun 17 23:04 test
 6 
 7 Linux 目录配置依据 FHS
 8 参考网址:http://www.pathname.com/fhs/
 9 规范两层:一层是 /
10      另一个层是 /usr,/var
11 绝对路径与相对路径
12 绝对路径:从/开头
13 相对路径:相对于当前位置的路径
14      .:当前目录
15       ..:上一层目录
16 /下目录浏览:
17 
18  1 [root@zkero ~]# ls -l /
19  2 total 102
20  3 dr-xr-xr-x.   2 root root  4096 May  3 21:24 bin
21  4 dr-xr-xr-x.   5 root root  1024 Apr 29 05:06 boot
22  5 drwxr-xr-x   18 root root  3780 Jun  9 18:17 dev
23  6 drwxr-xr-x. 106 root root 12288 Jun 17 23:04 etc
24  7 drwxr-xr-x.   6 root root  4096 Jun 17 23:03 home
25  8 dr-xr-xr-x.  10 root root  4096 Apr 29 04:58 lib
26  9 dr-xr-xr-x.   9 root root 12288 May  4 00:21 lib64
27 10 drwx------.   2 root root 16384 Apr 29 04:50 lost+found
28 11 drwxr-xr-x.   2 root root  4096 Sep 23  2011 media
29 12 drwxr-xr-x.   4 root root  4096 Jun  1 21:57 mnt
30 13 drwxr-xr-x.   3 root root  4096 Apr 28 21:13 opt
31 14 dr-xr-xr-x  123 root root     0 Jun  9 18:17 proc
32 15 dr-xr-x---.  29 root root  4096 Jun 17 23:03 root
33 16 dr-xr-xr-x.   2 root root 12288 Jun  3 01:02 sbin
34 17 drwxr-xr-x.   2 root root  4096 Apr 29 04:50 selinux
35 18 drwxr-xr-x.   2 root root  4096 Sep 23  2011 srv
36 19 drwxr-xr-x   13 root root     0 Jun  9 18:17 sys
37 20 drwxrwxrwt.  11 root root  4096 Jun  9 19:17 tmp
38 21 drwxr-xr-x.  13 root root  4096 Apr 29 04:50 usr
39 22 drwxr-xr-x.  22 root root  4096 May  4 00:59 var
40 其中root目录最好设置成 700

 s:特殊权限:set user id (s), set group id (s), sticky bit (t)  简称sst

set user id (s):执行文件以拥有者的权限执行 4000

set group id (s):执行文件以所属组的权限执行 2000

sticky bit (t):只有拥有者才能删除文件 1000

原来有x属性,加sst,会将x位变成s(s,t);若原来无x属性,则x位变成S(S,T)

举例:

1 [root@localhost ~]# ls -l test 
2 -rw-r--r--. 1 root root 0 Jul 17 01:16 test
3 [root@localhost ~]# chmod u+s test 
4 [root@localhost ~]# ls -l test 
5 -rwSr--r--. 1 root root 0 Jul 17 01:16 test
6 [root@localhost ~]# chmod u+x test 
7 [root@localhost ~]# ls -l test 
8 -rwsr--r--. 1 root root 0 Jul 17 01:16 test
原文地址:https://www.cnblogs.com/zker/p/4584681.html