文件权限-属性

导语

我们知道Linux操作系统是多用户操作系统,既然有不同的用户,就需要不同的权限控制,Linux中最高权限的用户是root用户,这一点同windows桌面版类似,windows里也分为普通用户和管理员用户,比如windows里的这个文本文件C:\Windows\System32\drivers\etc\hosts,如果不使用管理员用户是无权修改的

与windows桌面版不同的是,linux操作系统是可以支持多用户同时登陆,同时操作的,比如下面这张截图,使用w命令,显示了当前系统登陆的用户

`chmod a=rwx filename` 为所有用户增加(原来的权限自动取消)读写执行权限。
文件使用者有4中类型,u、g、o、a。分别表示user、group、others、all。
操作符包括三种类型,+、-、=,分别表示增加权限,删除权限、赋予给定的权限。
权限类型包括三种基本类型: r、w、x。
**数字化文件权限表示**。4表示r,2表示写,1表示执行,0表示-(没有权限)
举例说明:
	chmod a=rwx filename 相当于 chmod 777 filename
	chmod ug=rwx,o=- filename 相当于 chmod 770 filename

基础

[root@node1 ~]# ls -lrhti --full-time
total 58M
100714206 -rw-r--r-- 1 root root  58M 2019-07-18__16:01:20.000000000__+0800 sdf.tgz
101593497 -rw-r--r-- 1 root root 2.1K 2019-12-13__19:56:50.569818091__+0800 WordCount.java
100714223 -rw-r--r-- 1 root root 2.4K 2020-01-20__11:29:54.630501321__+0800 tmp.txt
100714203 -rw-r--r-- 1 root root   93 2020-01-31__12:21:25.427773664__+0800 test.sh
100714201 -rw-r--r-- 1 root root   46 2020-01-31__23:37:43.853462152__+0800 md5test.txt
102342061 -rw-r--r-- 1 root root 4.4K 2020-02-01__15:04:43.808931085__+0800 dp.txt
102342053 -rw-r--r-- 1 root root 4.8K 2020-02-01__22:30:55.842193520__+0800 ping.txt
100714200 -rw-r--r-- 1 root root    6 2020-02-01__22:37:40.014395993__+0800 hello.txt
  3111733 drwxr-xr-x 2 root root    6 2020-02-28__09:11:08.864116680__+0800 testdir

第1列 100714200 inode号码
第2列 -rw-r--r-- 文件权限 第1个表示文件类型 后面9位表示 owner group others的权限
第3列 表示硬连接数
第4列 文件的 owner 用户 
第5列 文件的 group 用户
第6列 文件或目录的大小
第7列 文件的修改时间
第8列 最后一列表示文件名

查看目录的及目录子目录和文件的大小可以用 du -sh testdir

文件的扩展名(格式)

Linux不同于windows不通过文件的扩展名直接区分文件类型,场景的Linux文件后缀扩展名有

.rpm  RedHat系统软件包
.tar.gz 压缩文件
.sh shell脚本
.conf 配置文件

可以通过file命令来判断文件的类型

[root@node1 ~]# file /etc/hostname 
/etc/hostname: ASCII text

Linux文件的类型

man find

       -type c
              File is of type c:
              b      block (buffered) special
              c      character (unbuffered) special
              d      directory
              p      named pipe (FIFO)
              f      regular file
              l      symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken.  If you  want  to  search  for  symbolic
                     links when -L is in effect, use -xtype.
              s      socket
              D      door (Solaris)

文件属性中的 - 表示 regular file

chmod

文件excrl的访问权限为rw-r--r--,现要增加所有用户的执行权限和同组用户写权限,命令是 ?
chmod a+x,g+w excrl

chown

stat

[root@10-255-20-218 ~]# stat tmp.txt 
  File: ‘tmp.txt’
  Size: 100       	Blocks: 8          IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 4444958     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-04-08 23:41:54.050799066 +0800
Modify: 2020-04-08 23:41:48.902726034 +0800
Change: 2020-04-08 23:41:48.907726104 +0800
 Birth: -