ls 显示目录下的内容和文件相关属性信息

1.命令功能

  ls命令是“list directory contents”,显示当前目录下的内容和文件属性。

2.语法格式

  ls  [option]  file

  ls  选项  文件名

3.选项说明

参数

参数说明

-a

显示全部文件包括隐藏文件,包括.和..

-A

显示全部文件,但是不包括.和..(列出除了”.”和“..”以外的文件)

-l

已长文件格式显示文件属性

-B

不要列出已~结尾的隐藏文件

-F

在每个文件的末尾添加一个标识符,通过标识符表明该文件的类型。“/”表示目录,“@”表示符号链接,“|”表示FIFOS,“=”表示套接字。

-t

按时间进行文件排序

-R

将目录下说有的子目录的文件都列出来。

-S

以文件大小进行排序。

  说明: linux文件的一些颜色含义:绿色:可执行文件;红色:压缩文件;深蓝色:目录;浅蓝色:链接文件;灰色:其它一些文件。

4. 使用范例

范例1 列出全部文件,包括隐藏文件

[root@localhost cxf]# ls -a

.  ..  .bash_history  .bash_logout  .bash_profile  .bashrc  dir1  dir2  .lesshst  test

范例2 列出除了”.”和“..”以外的文件

[root@localhost cxf]# ls -A

.bash_history  .bash_logout  .bash_profile  .bashrc  dir1  dir2  .lesshst  test

范例3 长格式显示文件属性信息

[root@localhost cxf]# ls -l

total 12

drwxr-xr-x. 2 root root 4096 Mar 13 16:43 dir1

drwxr-xr-x. 2 root root 4096 Mar 13 16:43 dir2

-rw-r--r--. 1 root root   12 Mar 13 16:41 test

范例4 在文件尾加上标识符

[root@localhost cxf]# ls -F

dir1/  dir2/  test

[root@localhost cxf]# ls -lF

total 12

drwxr-xr-x. 2 root root 4096 Mar 13 16:43 dir1/

drwxr-xr-x. 2 root root 4096 Mar 13 16:43 dir2/

-rw-r--r--. 1 root root   12 Mar 13 16:41 test

范例5 显示目录下的所有子目录

[root@localhost cxf]# ls -R

.:

dir1  dir2  ok  test

./dir1:

./dir2:

./ok:

a

./ok/a:

b

./ok/a/b:

c

./ok/a/b/c:

原文地址:https://www.cnblogs.com/joechu/p/8618072.html