ls命令 & 文件和目录属性

文件和目录属性

[root@centos-01 ~]# ls -l
总用量 4
-rw-------. 1 root root 1418 1227 05:29 anaconda-ks.cfg

共显示了9列内容

  • 第1列,包含该文件类型和所属主、所属组以及其他用户对该文件的权限。第一列共11位(有的文件是10位,没有最后面的一位)。 其中第一位用来描述该文件的类型。

文件类型

缩写 含义
‘d’ 表示该文件为目录
‘-’ 表示该文件为普通文件
‘l’ 表示该文件为链接文件
‘b’ 表示该文件为块设备,比如/dev/sda就是这样的文件
‘c’ 表示该文件为字符串设备(串行端口设备),例如键盘、鼠标
‘s’ 表示该文件为套接字文件(socket),用于进程间通信

后边的9位,每三个为一组。均为rwx三个参数的组合。其中r代表可读,w代表可写,x代表可执行。前三位为所属主(user)的权限,中间三位为所属组(group)的权限,最后三位为其他非本群组(others)的权限。也可用数字表示权限,r=4,w=2,x=1,rwx=7,rw-=6,–x=1,rw-r–r–=644,rw-r-xr-x=655。

第一列的最后一位的‘.’(点),之前的CentOS 5是没有这个点的,这主要是因为新版本的ls把selinux或者acl的属性加进来了。当文件或者目录只使用了selinux context的属性,这里是一个点。如果设置了acl,后面将是一个加号‘+’。

  • 第2列,表示链接占用的节点(inode)。为目录时,通常与该目录底下还有多少目录有关系。

  • 第3列,表示该文件的所属主(所有者)

  • 第4列,表示该文件的所属组(用户组)

  • 第5列,表示该文件的大小(单位:B字节)

  • 第6列第7列第8列为该文件的最近的修改日期,分别为月份日期以及时间,也就是所谓的mtime

  • 第9列,文件名。


-i:文件的inode号

[root@centos-01 ~]# ls -i anaconda-ks.cfg 
33582978 anaconda-ks.cfg

-h:自动变换单位,这里以KB显示文件的大小

[root@centos-01 ~]# ls -lh anaconda-ks.cfg 
-rw-------. 1 root root 1.4K 1227 05:29 anaconda-ks.cfg

-a:查看目录下所有文件、目录,包括隐藏的

[root@centos-01 ~]# ls -la
总用量 28
dr-xr-x---.  3 root root  147 1月   1 10:43 .
dr-xr-xr-x. 17 root root  224 1月  16 18:31 ..
-rw-------.  1 root root 1418 12月 27 05:29 anaconda-ks.cfg
-rw-------.  1 root root 1068 1月  18 17:22 .bash_history
-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
drwx------.  2 root root   48 1月  18 15:40 .ssh
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc

:一个点“.”是当前目录,两个点“..”是上一层目录。

-t:按时间排序

[root@centos-01 ~]# ls -lta
总用量 28
-rw-------.  1 root root 1068 1月  18 17:22 .bash_history
drwx------.  2 root root   48 1月  18 15:40 .ssh
dr-xr-xr-x. 17 root root  224 1月  16 18:31 ..
dr-xr-x---.  3 root root  147 1月   1 10:43 .
-rw-------.  1 root root 1418 12月 27 05:29 anaconda-ks.cfg
-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc
[root@centos-01 ~]# ls -la
总用量 28
dr-xr-x---.  3 root root  147 1月   1 10:43 .
dr-xr-xr-x. 17 root root  224 1月  16 18:31 ..
-rw-------.  1 root root 1418 12月 27 05:29 anaconda-ks.cfg
-rw-------.  1 root root 1068 1月  18 17:22 .bash_history
-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
drwx------.  2 root root   48 1月  18 15:40 .ssh
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc

猜你喜欢

转载自blog.csdn.net/noob_f/article/details/79404651