(1)命令功能
ls命令用来显示目标列表,在Linux系统中有着较高的使用率。ls命令的输出信息可以进行彩色加亮显示,以区分不同类型的文件。
(2)命令语法
ls(选项) (参数)
(3)选项说明
-
-a:显示所有档案及目录(ls内定将档案名或目录名称开关为“.”的视为隐藏档,不会列出;
-
-C:多列显示输出结果。这是默认选项;
-
-i:显示目录或文件的inode索引号;
-
-h:在ls –l的输出中,把文件大小的显示改变为用KB表示(默认为字节);
-
-1(数字):与“C”选项功能相反,所有输出信息用单列格式输出,不输出为多列;
-
-d:仅显示目录名,而不显示目录下的内容列表;
-
-l:以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名,文件类型、权限模式、硬连接数、所有者、组、文件大小和文件的最后修改时间等;
-
-R:递归处理,将指定目录下的所有文件及子目录一并处理。
(4)参数说明
-
目录:指定要显示列表的目录。也可以是具体的文件。
(5)实例
实例1:显示当前目录下非隐藏文件与目录—ls .
1
2
3
4
|
[root@moban /]# ls .
a boot dev leaf lib64 mnt opt sbin sys test3
var
b c etc leafhao lost+found mydisk proc selinux test1 tmp xphao
bin data home lib media oldboy root srv test2 usr xpleaf
|
实例2:显示当前目录下包括隐藏文件在内的所有文件列表—ls –a
1
2
3
4
5
6
|
[root@moban /]# ls -a
. b dev lib mydisk sbin test2 xphao
.. bin etc lib64 oldboy selinux test3 xpleaf
a boot home lost+found opt srv tmp
.autofsck c leaf media proc sys usr
.autorelabel data leafhao mnt root test1
var
|
实例3:列出文件和文件夹详细信息—ls –l
1
2
3
4
5
6
7
8
|
[root@moban /]# ls -l
total
146
drwxr-xr-x.
2
root root
4096
May
13
19
:
46
a
drwxr-xr-x.
2
root root
4096
May
13
19
:
46
b
dr-xr-xr-x.
2
root root
4096
May
22
19
:
26
bin
dr-xr-xr-x.
5
root root
1024
May
13
23
:
49
boot
drwxr-xr-x.
2
root root
4096
May
13
19
:
46
c
省略······
|
实例4:递归显示文件—ls –R
1
2
3
4
5
6
|
[root@moban /]# ls -R /xpleaf
/xpleaf:
leaf test.txt xpleaf
/xpleaf/leaf:
xpleaf.txt
|
实例5:显示文件夹信息—ls –ld 目录/文件
1
2
|
[root@moban /]# ls -ld /etc
drwxr-xr-x.
84
rootroot
4096
Jun
25
22
:
15
/etc
|
说明:不加-ld参数,会将/etc目录下的所有子目录和文件显示出来
实例6:以列输出显示当前目录下非隐藏文件与目录—ls -1(数字)
1
2
3
4
5
|
[root@moban /]# ls -
1
bin
boot
data
省略······
|
实例7:ls –ld,只能显示当前目录的详细信息
1
2
3
4
|
[root@moban /]# ls -d
.
[root@moban /]# ls -ld
dr-xr-xr-x.
35
rootroot
4096
Jun
25
21
:
45
.
|
实例8:显示目录或文件的inode索引号—ls–li
1
2
|
[root@moban ~]# ls -li test.txt
271579
-rw-r--r-- 1root root
7
Jul
2
08
:
32
test.txt
|
实例9:把文件大小的显示改变为用KB表示—ls–lh
1
2
3
4
|
[root@moban ~]# ls -l c.docx
-rw-r--r--
1
rootroot
27119
Jun
30
22
:
46
c.docx
[root@moban ~]# ls-lh c.docx
-rw-r--r--
1
rootroot 27K Jun
30
22
:
46
c.docx
|
本文转自 xpleaf 51CTO博客,原文链接:http://blog.51cto.com/xpleaf/1671111,如需转载请自行联系原作者