ls

【功能说明】:

list directory contents  #列出目录内容

☆ 可同时列出多个目录内容


【语法格式】:

ls [OPTION]... [FILE]...

 

【选项参数】:

参数说明
-a, --all全部文件,连隐藏文件(开头为 . 的文件)一起列出来
-A, --almost-all同上,但不包括 . 和 .. 这两个目录
-d, --directory列出目录本身,而不是目录里面的文件
-F, --classify根据文件的类型,附加一些指标进行记录,例如:* 代表可执行文件; / 代表目录 等等;
-h, --human-readable将文件容量以常见格式显示(例如 K M G)
-i, --inode显示文件的inode 号码
-l以长格式显示,包括文件的权限、属性等信息
-n, --numeric-uid-gid列出文件的UID和GID号码,而非用户和用户组的名称
-r, --reverse将排序结果反向输出
-R, --recursive连同子目录内容一起列出来,等于该目录下所有文件都显示出来
-S 以文件容量排序(默认是以文件名排序)
-t以文件修改时间排序
--color[=WHEN]选择文件输出颜色,默认是“=always”:始终显示颜色,也可设置为“=never”:不显示颜色,“=auto”:让系统自行决定是否显示颜色
--full-time以完整时间(包含年、月、日、时、分)显示
--time={atime,ctime}输出访问时间或权限改变时间,而非内容更改时间(默认显示时间)

 

【实践操作】:

1、列出/tmp 目录下所有文件(包括隐藏文件),注意以 . 开头的文件

 [root@Mode tmp]# ls -a

.  ..  .ICE-unix  a.txt  b.txt  c.txt  ssh-ZItOgj4510


2、同上,但要求不显示 . 和 .. 目录,注意与上面的区别

[root@Mode tmp]# ls -A /tmp/

.ICE-unix  a.txt  b.txt  c.txt  ssh-ZItOgj4510


3、查看/tmp 目录本身的属性,注意加了 –d 参数后的变化

[root@Mode tmp]# ls -l /tmp/

total 4

-rw-r--r--. 1 root root    0 May 17 10:45 a.txt

-rw-r--r--. 1 root root    0 May 17 10:45 b.txt

-rw-r--r--. 1 root root    0 May 17 10:45 c.txt

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510

[root@Mode tmp]# ls -ld /tmp/

drwxrwxrwt. 4 root root 4096 May 17 14:20 /tmp/


4、列出/tmp 目录下的内容,并显示文件类型。 文件名后面有/ ,表示这是个目录

[root@Mode tmp]# ls -F /tmp/

a.txt  b.txt  c.txt  ssh-ZItOgj4510/


5、列出/tmp 目录下的内容,并以易读的方式显示文件容量大小

[root@Mode tmp]# ls -l /tmp/

total 4

-rw-r--r--. 1 root root    0 May 17 10:45 a.txt

-rw-r--r--. 1 root root    0 May 17 10:45 b.txt

-rw-r--r--. 1 root root    0 May 17 10:45 c.txt

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510

[root@Mode tmp]# ls -hl /tmp/

total 4.0K

-rw-r--r--. 1 root root    0 May 17 10:45 a.txt

-rw-r--r--. 1 root root    0 May 17 10:45 b.txt

-rw-r--r--. 1 root root    0 May 17 10:45 c.txt

drwx------. 2 root root 4.0K May 17 14:20 ssh-ZItOgj4510


6、列出/tmp 目录下的内容,并显示各文件的inode号码(可用于查看两个文件是否为硬连接文件

[root@Mode tmp]# ll -ai

total 20

130051 drwxrwxrwt.  4 root root 4096 May 17 14:50 .

     2 dr-xr-xr-x. 24 root root 4096 May 17 10:49 ..

130061 drwxrwxrwt.  2 root root 4096 May 16 16:20 .ICE-unix

130052 -rw-r--r--.  1 root root    0 May 17 14:38 a.txt

133230 -rw-r--r--.  1 root root   27 May 17 14:33 b.txt

133233 -rw-rw-rw-.  1 root root    0 May 17 10:45 c.txt

133240 drwx------.  2 root root 4096 May 17 14:20 ssh-ZItOgj4510

[root@Mode tmp]# ll -id /tmp

130051 drwxrwxrwt. 4 root root 4096 May 17 14:50 /tmp


7、列出/tmp 目录下的内容,并显示各文件的属性及权限,这个参数使用很频繁,非常重要

[root@Mode tmp]# ll        

total 8

-rw-r--r--. 1 root root    0 May 17 10:45 a.txt

-rw-r--r--. 1 root root   27 May 17 14:33 b.txt

-rw-r--r--. 1 root root    0 May 17 10:45 c.txt

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510


8、列出/tmp 目录下的内容,并显示UID和GID号,而非用户和用户组的名称,可与上面比较

[root@Mode tmp]# ls -ln /tmp/

total 4

-rw-r--r--. 1 0 0    0 May 17 10:45 a.txt

-rw-r--r--. 1 0 0    0 May 17 10:45 b.txt

-rw-r--r--. 1 0 0    0 May 17 10:45 c.txt

drwx------. 2 0 0 4096 May 17 14:20 ssh-ZItOgj4510


9、列出/tmp 目录下的内容,将排序结果反向输出

[root@Mode tmp]# ll        

total 8

-rw-r--r--. 1 root root    0 May 17 10:45 a.txt

-rw-r--r--. 1 root root   27 May 17 14:33 b.txt

-rw-r--r--. 1 root root    0 May 17 10:45 c.txt

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510

[root@Mode tmp]# ls -rl /tmp/

total 4

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510

-rw-r--r--. 1 root root    0 May 17 10:45 c.txt

-rw-r--r--. 1 root root    0 May 17 10:45 b.txt

-rw-r--r--. 1 root root    0 May 17 10:45 a.txt


10、列出/tmp目录下所有内容,包括子目录中的内容 

[root@Mode tmp]# ls -R /tmp/

/tmp/:

a.txt  b.txt  c.txt  ssh-ZItOgj4510


/tmp/ssh-ZItOgj4510:

agent.4510


11、列出/tmp目录下所有内容,以文件容量大小排序

[root@Mode tmp]# ls -lS 

total 8

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510

-rw-r--r--. 1 root root   27 May 17 14:33 b.txt

-rw-r--r--. 1 root root    0 May 17 10:45 a.txt

-rw-r--r--. 1 root root    0 May 17 10:45 c.txt


12、列出/tmp目录下所有内容,已修改时间排序。方便查看哪个是最新修改过的文件

[root@Mode tmp]# ll -t

total 8

-rw-r--r--. 1 root root   27 May 17 14:33 b.txt

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510

-rw-r--r--. 1 root root    0 May 17 10:45 a.txt

-rw-r--r--. 1 root root    0 May 17 10:45 c.txt

 

13、列出/tmp目录下所有内容,且不显示颜色

 wKiom1Vb4IXigi9bAACzISgTsY0025.jpg


14、列出/tmp目录下所有内容,并已完整时间模式输出

[root@Mode tmp]# ll --full-time

total 8

-rw-r--r--. 1 root root    0 2015-05-17 10:45:31.643481041 +0800 a.txt

-rw-r--r--. 1 root root   27 2015-05-17 14:33:12.721438364 +0800 b.txt

-rw-r--r--. 1 root root    0 2015-05-17 10:45:31.643481041 +0800 c.txt

drwx------. 2 root root 4096 2015-05-17 14:20:59.494451094 +0800 ssh-ZItOgj4510


15、列出/tmp目录下所有内容,并显示文件的访问时间或权限修改时间,而非默认的内容修改时间

[root@Mode tmp]# ll      #显示默认的内容修改时间

total 8

-rw-r--r--. 1 root root    0 May 17 14:38 a.txt

-rw-r--r--. 1 root root   27 May 17 14:33 b.txt

-rw-rw-rw-. 1 root root    0 May 17 10:45 c.txt

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510

[root@Mode tmp]# ll --time=atime        #显示文件的访问时间

total 8

-rw-r--r--. 1 root root    0 May 17 14:38 a.txt

-rw-r--r--. 1 root root   27 May 17 10:45 b.txt

-rw-rw-rw-. 1 root root    0 May 17 10:45 c.txt

drwx------. 2 root root 4096 May 17 14:32 ssh-ZItOgj4510

[root@Mode tmp]# ll --time=ctime #显示文件的权限修改时间

total 8

-rw-r--r--. 1 root root    0 May 17 14:38 a.txt

-rw-r--r--. 1 root root   27 May 17 14:33 b.txt

-rw-rw-rw-. 1 root root    0 May 17 14:38 c.txt

drwx------. 2 root root 4096 May 17 14:20 ssh-ZItOgj4510


此命令参考鸟哥书籍