Skip to content

Commit b2e7d41

Browse files
committed
添加ls 命令
1 parent 8dce2c8 commit b2e7d41

1 file changed

Lines changed: 178 additions & 0 deletions

File tree

‎command/ls.md‎

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
2+
ls
3+
===
4+
5+
显示目标列表
6+
7+
## 补充说明
8+
9+
**ls命令** 用来显示目标列表,在Linux中是使用率较高的命令。ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件。
10+
11+
## 语法
12+
13+
```bash
14+
ls(选项)(参数)
15+
```
16+
17+
## 选项
18+
19+
- -a:显示所有档案及目录(ls内定将档案名或目录名称为“.”的视为影藏,不会列出);
20+
- -A:显示除影藏文件“.”和“..”以外的所有文件列表;
21+
- -C:多列显示输出结果。这是默认选项;
22+
- -l:与“-C”选项功能相反,所有输出信息用单列格式输出,不输出为多列;
23+
- -F:在每个输出项后追加文件的类型标识符,具体含义:“*”表示具有可执行权限的普通文件,“/”表示目录,“@”表示符号链接,“|”表示命令管道FIFO,“=”表示sockets套接字。当文件为普通文件时,不输出任何标识符;
24+
- -b:将文件中的不可输出的字符以反斜线“”加字符编码的方式输出;
25+
- -c:与“-lt”选项连用时,按照文件状态时间排序输出目录内容,排序的依据是文件的索引节点中的ctime字段。与“-l”选项连用时,则排序的一句是文件的状态改变时间;
26+
- -d:仅显示目录名,而不显示目录下的内容列表。显示符号链接文件本身,而不显示其所指向的目录列表;
27+
- -f:此参数的效果和同时指定“aU”参数相同,并关闭“lst”参数的效果;
28+
- -i:显示文件索引节点号(inode)。一个索引节点代表一个文件;
29+
- --file-type:与“-F”选项的功能相同,但是不显示“*”;
30+
- -k:以KB(千字节)为单位显示文件大小;
31+
- -l:以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名,文件类型、权限模式、硬连接数、所有者、组、文件大小和文件的最后修改时间等;
32+
- -m:用“,”号区隔每个文件和目录的名称;
33+
- -n:以用户识别码和群组识别码替代其名称;
34+
- -r:以文件名反序排列并输出目录内容列表;
35+
- -s:显示文件和目录的大小,以区块为单位;
36+
- -t:用文件和目录的更改时间排序;
37+
- -L:如果遇到性质为符号链接的文件或目录,直接列出该链接所指向的原始文件或目录;
38+
- -R:递归处理,将指定目录下的所有文件及子目录一并处理;
39+
- --full-time:列出完整的日期与时间;
40+
- --color[=WHEN]:使用不同的颜色高亮显示不同类型的。
41+
42+
## 参数
43+
44+
目录:指定要显示列表的目录,也可以是具体的文件。
45+
46+
## 实例
47+
48+
显示当前目录下非影藏文件与目录
49+
50+
```bash
51+
ls # 显示当前目录下非影藏文件与目录
52+
ls -a # 显示当前目录下包括影藏文件在内的所有文件列表
53+
ls -m # 水平输出文件列表
54+
ls -t # 最近修改的文件显示在最上面
55+
ls -R # 显示递归文件
56+
ls -F # 按照特殊字符对文件进行分类
57+
ls --color=auto # 列出文件并标记颜色分类
58+
```
59+
60+
输出长格式列表
61+
62+
```bash
63+
ls -1
64+
65+
anaconda-ks.cfg
66+
install.log
67+
install.log.syslog
68+
satools
69+
```
70+
71+
显示文件的inode信息
72+
73+
索引节点(index inode简称为“inode”)是Linux中一个特殊的概念,具有相同的索引节点号的两个文本本质上是同一个文件(除文件名不同外)。
74+
75+
```bash
76+
ls -i -l anaconda-ks.cfg install.log
77+
78+
2345481 -rw------- 1 root root 859 Jun 11 22:49 anaconda-ks.cfg
79+
2345474 -rw-r--r-- 1 root root 13837 Jun 11 22:49 install.log
80+
```
81+
82+
显示递归文件
83+
84+
```bash
85+
ls -R
86+
87+
.:
88+
css gulpfile.js img index.html package.json README.md styl
89+
90+
./css:
91+
index.min.css
92+
93+
./img:
94+
logo.svg
95+
96+
./styl:
97+
index.styl reset.styl
98+
```
99+
100+
打印文件的UID和GID
101+
102+
```bash
103+
ls -n
104+
105+
total 254
106+
drwxr-xr-x 2 0 0 4096 Jun 12 04:03 bin
107+
drwxr-xr-x 4 0 0 1024 Jun 15 14:45 boot
108+
drwxr-xr-x 6 0 0 4096 Jun 12 10:26 data
109+
drwxr-xr-x 10 0 0 3520 Sep 26 15:38 dev
110+
drwxr-xr-x 75 0 0 4096 Oct 16 04:02 etc
111+
drwxr-xr-x 4 0 0 4096 Jun 12 10:26 home
112+
drwxr-xr-x 14 0 0 12288 Jun 16 04:02 lib
113+
```
114+
115+
列出文件和文件夹的详细信息
116+
117+
```bash
118+
ls -l
119+
120+
total 254
121+
drwxr-xr-x 2 root root 4096 Jun 12 04:03 bin
122+
drwxr-xr-x 4 root root 1024 Jun 15 14:45 boot
123+
drwxr-xr-x 6 root root 4096 Jun 12 10:26 data
124+
drwxr-xr-x 10 root root 3520 Sep 26 15:38 dev
125+
drwxr-xr-x 75 root root 4096 Oct 16 04:02 etc
126+
```
127+
128+
列出可读文件和文件夹详细信息
129+
130+
```bash
131+
ls -lh
132+
133+
total 254K
134+
drwxr-xr-x 2 root root 4.0K Jun 12 04:03 bin
135+
drwxr-xr-x 4 root root 1.0K Jun 15 14:45 boot
136+
drwxr-xr-x 6 root root 4.0K Jun 12 10:26 data
137+
drwxr-xr-x 10 root root 3.5K Sep 26 15:38 dev
138+
drwxr-xr-x 75 root root 4.0K Oct 16 04:02 etc
139+
drwxr-xr-x 4 root root 4.0K Jun 12 10:26 home
140+
```
141+
142+
显示文件夹信息
143+
144+
```bash
145+
ls -ld /etc/
146+
147+
drwxr-xr-x 75 root root 4096 Oct 16 04:02 /etc/
148+
```
149+
150+
按时间列出文件和文件夹详细信息
151+
152+
```bash
153+
ls -lt
154+
155+
total 254
156+
drwxrwxrwt 3 root root 98304 Oct 16 08:53 tmp
157+
drwxr-xr-x 75 root root 4096 Oct 16 04:02 etc
158+
drwxr-x--- 4 root root 4096 Oct 15 14:43 root
159+
drwxr-xr-x 10 root root 3520 Sep 26 15:38 dev
160+
drwxr-xr-x 14 root root 12288 Jun 16 04:02 lib
161+
drwxr-xr-x 2 root root 4096 May 11 2011 srv
162+
drwxr-xr-x 2 root root 4096 Nov 8 2010 misc
163+
```
164+
165+
按修改时间列出文件和文件夹详细信息
166+
167+
```bash
168+
ls -ltr
169+
170+
total 254
171+
drwxr-xr-x 2 root root 4096 Nov 8 2010 misc
172+
drwxr-xr-x 2 root root 4096 May 11 2011 srv
173+
drwxr-xr-x 2 root root 4096 May 11 2011 selinux
174+
drwxr-xr-x 2 root root 4096 May 11 2011 opt
175+
drwxr-xr-x 2 root root 4096 May 11 2011 mnt
176+
drwxr-xr-x 75 root root 4096 Oct 16 04:02 etc
177+
drwxrwxrwt 3 root root 98304 Oct 16 08:54 tmp
178+
```

0 commit comments

Comments
 (0)