You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
9.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# ls
显示目录内容列表
## 说明
**ls命令** 用来显示目标列表在Linux中是使用率较高的命令。ls命令的输出信息可以进行彩色加亮显示以分区不同类型的文件。
## 选项
```sh
-a显示所有档案及目录连同隐藏档开头为.文件一起罗列出来);
-A显示全部文件和目录连同隐藏文件但不包括.和..这两个目录;
-C多列显示输出结果。这是默认选项
-l与“-C”选项功能相反所有输出信息用单列格式输出不输出为多列
-F在每个输出项后追加文件的类型标识符具体含义“*”表示具有可执行权限的普通文件,“/”表示目录,“@”表示符号链接,“|”表示命令管道FIFO=”表示sockets套接字。当文件为普通文件时不输出任何标识符
-b将文件中的不可输出的字符以反斜线“”加字符编码的方式输出
-c与“-lt”选项连用时按照文件状态时间排序输出目录内容排序的依据是文件的索引节点中的ctime字段。与“-l”选项连用时则排序的一句是文件的状态改变时间
-d仅显示目录名而不显示目录下的内容列表。显示符号链接文件本身而不显示其所指向的目录列表
-f此参数的效果和同时指定“aU”参数相同并关闭“lst”参数的效果
-i显示文件索引节点号inode。一个索引节点代表一个文件
--file-type与“-F”选项的功能相同但是不显示“*”;
-k以KB千字节为单位显示文件大小
-h:将文件容量以人类易读的方式显示
-l以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名文件类型、权限模式、硬连接数、所有者、组、文件大小和文件的最后修改时间等
-m用“,”号区隔每个文件和目录的名称;
-n以用户识别码和群组识别码替代其名称
-r以文件名反序排列并输出目录内容列表
-s显示文件和目录的大小以区块为单位
-S: 以文件大小排序,最大的优先(降序)
-t用文件和目录的更改时间排序
-L如果遇到性质为符号链接的文件或目录直接列出该链接所指向的原始文件或目录
-R递归处理将指定目录下的所有文件及子目录一并处理
--full-time列出完整的日期与时间
--color[=WHEN]:使用不同的颜色高亮显示不同类型的。
```
### 参数
目录:指定要显示列表的目录,也可以是具体的文件。
### 实例
```sh
ls # 仅列出当前目录可见文件
ls -l # 列出当前目录可见文件详细信息
ls -hl # 列出详细信息并以可读大小显示文件大小
ls -al # 列出所有文件(包括隐藏)的详细信息
```
显示文件的inode信息
索引节点index inode简称为“inode”是Linux中一个特殊的概念具有相同的索引节点号的两个文本本质上是同一个文件除文件名不同外
```
[root@localhost ~]# ls -i -l anaconda-ks.cfg install.log
2345481 -rw------- 1 root root 859 Jun 11 22:49 anaconda-ks.cfg
2345474 -rw-r--r-- 1 root root 13837 Jun 11 22:49 install.log
```
水平输出文件列表
```
[root@localhost /]# ls -m
bin, boot, data, dev, etc, home, lib, lost+found, media, misc, mnt, opt, proc, root, sbin, selinux, srv, sys, tmp, usr, var
```
修改最后一次编辑的文件
最近修改的文件显示在最上面。
```
[root@localhost /]# ls -t
tmp root etc dev lib boot sys proc data home bin sbin usr var lost+found media mnt opt selinux srv misc
```
显示递归文件
```
[root@localhost ~]# ls -R
.:
anaconda-ks.cfg install.log install.log.syslog satools
./satools:
black.txt freemem.sh iptables.sh lnmp.sh mysql php502_check.sh ssh_safe.sh
```
打印文件的UID和GID
```
[root@localhost /]# ls -n
total 254
drwxr-xr-x 2 0 0 4096 Jun 12 04:03 bin
drwxr-xr-x 4 0 0 1024 Jun 15 14:45 boot
drwxr-xr-x 6 0 0 4096 Jun 12 10:26 data
drwxr-xr-x 10 0 0 3520 Sep 26 15:38 dev
drwxr-xr-x 75 0 0 4096 Oct 16 04:02 etc
drwxr-xr-x 4 0 0 4096 Jun 12 10:26 home
drwxr-xr-x 14 0 0 12288 Jun 16 04:02 lib
drwx------ 2 0 0 16384 Jun 11 22:46 lost+found
drwxr-xr-x 2 0 0 4096 May 11 2011 media
drwxr-xr-x 2 0 0 4096 Nov 8 2010 misc
drwxr-xr-x 2 0 0 4096 May 11 2011 mnt
drwxr-xr-x 2 0 0 4096 May 11 2011 opt
dr-xr-xr-x 232 0 0 0 Jun 15 11:04 proc
drwxr-x--- 4 0 0 4096 Oct 15 14:43 root
drwxr-xr-x 2 0 0 12288 Jun 12 04:03 sbin
drwxr-xr-x 2 0 0 4096 May 11 2011 selinux
drwxr-xr-x 2 0 0 4096 May 11 2011 srv
drwxr-xr-x 11 0 0 0 Jun 15 11:04 sys
drwxrwxrwt 3 0 0 98304 Oct 16 08:45 tmp
drwxr-xr-x 13 0 0 4096 Jun 11 23:38 usr
drwxr-xr-x 19 0 0 4096 Jun 11 23:38 var
```
列出文件和文件夹的详细信息
```
[root@localhost /]# ls -l
total 254
drwxr-xr-x 2 root root 4096 Jun 12 04:03 bin
drwxr-xr-x 4 root root 1024 Jun 15 14:45 boot
drwxr-xr-x 6 root root 4096 Jun 12 10:26 data
drwxr-xr-x 10 root root 3520 Sep 26 15:38 dev
drwxr-xr-x 75 root root 4096 Oct 16 04:02 etc
drwxr-xr-x 4 root root 4096 Jun 12 10:26 home
drwxr-xr-x 14 root root 12288 Jun 16 04:02 lib
drwx------ 2 root root 16384 Jun 11 22:46 lost+found
drwxr-xr-x 2 root root 4096 May 11 2011 media
drwxr-xr-x 2 root root 4096 Nov 8 2010 misc
drwxr-xr-x 2 root root 4096 May 11 2011 mnt
drwxr-xr-x 2 root root 4096 May 11 2011 opt
dr-xr-xr-x 232 root root 0 Jun 15 11:04 proc
drwxr-x--- 4 root root 4096 Oct 15 14:43 root
drwxr-xr-x 2 root root 12288 Jun 12 04:03 sbin
drwxr-xr-x 2 root root 4096 May 11 2011 selinux
drwxr-xr-x 2 root root 4096 May 11 2011 srv
drwxr-xr-x 11 root root 0 Jun 15 11:04 sys
drwxrwxrwt 3 root root 98304 Oct 16 08:48 tmp
drwxr-xr-x 13 root root 4096 Jun 11 23:38 usr
drwxr-xr-x 19 root root 4096 Jun 11 23:38 var
```
列出可读文件和文件夹详细信息
```
[root@localhost /]# ls -lh
total 254K
drwxr-xr-x 2 root root 4.0K Jun 12 04:03 bin
drwxr-xr-x 4 root root 1.0K Jun 15 14:45 boot
drwxr-xr-x 6 root root 4.0K Jun 12 10:26 data
drwxr-xr-x 10 root root 3.5K Sep 26 15:38 dev
drwxr-xr-x 75 root root 4.0K Oct 16 04:02 etc
drwxr-xr-x 4 root root 4.0K Jun 12 10:26 home
drwxr-xr-x 14 root root 12K Jun 16 04:02 lib
drwx------ 2 root root 16K Jun 11 22:46 lost+found
drwxr-xr-x 2 root root 4.0K May 11 2011 media
drwxr-xr-x 2 root root 4.0K Nov 8 2010 misc
drwxr-xr-x 2 root root 4.0K May 11 2011 mnt
drwxr-xr-x 2 root root 4.0K May 11 2011 opt
dr-xr-xr-x 235 root root 0 Jun 15 11:04 proc
drwxr-x--- 4 root root 4.0K Oct 15 14:43 root
drwxr-xr-x 2 root root 12K Jun 12 04:03 sbin
drwxr-xr-x 2 root root 4.0K May 11 2011 selinux
drwxr-xr-x 2 root root 4.0K May 11 2011 srv
drwxr-xr-x 11 root root 0 Jun 15 11:04 sys
drwxrwxrwt 3 root root 96K Oct 16 08:49 tmp
drwxr-xr-x 13 root root 4.0K Jun 11 23:38 usr
drwxr-xr-x 19 root root 4.0K Jun 11 23:38 var
```
显示文件夹信息
```
[root@localhost /]# ls -ld /etc/
drwxr-xr-x 75 root root 4096 Oct 16 04:02 /etc/
```
按时间列出文件和文件夹详细信息
```
[root@localhost /]# ls -lt
total 254
drwxrwxrwt 3 root root 98304 Oct 16 08:53 tmp
drwxr-xr-x 75 root root 4096 Oct 16 04:02 etc
drwxr-x--- 4 root root 4096 Oct 15 14:43 root
drwxr-xr-x 10 root root 3520 Sep 26 15:38 dev
drwxr-xr-x 14 root root 12288 Jun 16 04:02 lib
drwxr-xr-x 4 root root 1024 Jun 15 14:45 boot
drwxr-xr-x 11 root root 0 Jun 15 11:04 sys
dr-xr-xr-x 232 root root 0 Jun 15 11:04 proc
drwxr-xr-x 6 root root 4096 Jun 12 10:26 data
drwxr-xr-x 4 root root 4096 Jun 12 10:26 home
drwxr-xr-x 2 root root 4096 Jun 12 04:03 bin
drwxr-xr-x 2 root root 12288 Jun 12 04:03 sbin
drwxr-xr-x 13 root root 4096 Jun 11 23:38 usr
drwxr-xr-x 19 root root 4096 Jun 11 23:38 var
drwx------ 2 root root 16384 Jun 11 22:46 lost+found
drwxr-xr-x 2 root root 4096 May 11 2011 media
drwxr-xr-x 2 root root 4096 May 11 2011 mnt
drwxr-xr-x 2 root root 4096 May 11 2011 opt
drwxr-xr-x 2 root root 4096 May 11 2011 selinux
drwxr-xr-x 2 root root 4096 May 11 2011 srv
drwxr-xr-x 2 root root 4096 Nov 8 2010 misc
```
按修改时间列出文件和文件夹详细信息
```
[root@localhost /]# ls -ltr
total 254
drwxr-xr-x 2 root root 4096 Nov 8 2010 misc
drwxr-xr-x 2 root root 4096 May 11 2011 srv
drwxr-xr-x 2 root root 4096 May 11 2011 selinux
drwxr-xr-x 2 root root 4096 May 11 2011 opt
drwxr-xr-x 2 root root 4096 May 11 2011 mnt
drwxr-xr-x 2 root root 4096 May 11 2011 media
drwx------ 2 root root 16384 Jun 11 22:46 lost+found
drwxr-xr-x 19 root root 4096 Jun 11 23:38 var
drwxr-xr-x 13 root root 4096 Jun 11 23:38 usr
drwxr-xr-x 2 root root 12288 Jun 12 04:03 sbin
drwxr-xr-x 2 root root 4096 Jun 12 04:03 bin
drwxr-xr-x 4 root root 4096 Jun 12 10:26 home
drwxr-xr-x 6 root root 4096 Jun 12 10:26 data
dr-xr-xr-x 232 root root 0 Jun 15 11:04 proc
drwxr-xr-x 11 root root 0 Jun 15 11:04 sys
drwxr-xr-x 4 root root 1024 Jun 15 14:45 boot
drwxr-xr-x 14 root root 12288 Jun 16 04:02 lib
drwxr-xr-x 10 root root 3520 Sep 26 15:38 dev
drwxr-x--- 4 root root 4096 Oct 15 14:43 root
drwxr-xr-x 75 root root 4096 Oct 16 04:02 etc
drwxrwxrwt 3 root root 98304 Oct 16 08:54 tmp
```
按照特殊字符对文件进行分类
```
[root@localhost nginx-1.2.1]# ls -F
auto/ CHANGES CHANGES.ru conf/ configure* contrib/ html/ LICENSE Makefile man/ objs/ README src/
```
列出文件并标记颜色分类
```
[root@localhost nginx-1.2.1]# ls --color=auto
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
```
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->