每天一个Linux命令(3):ls命令

ls命令用来显示目标列表,在Linux中是使用率较高的命令。ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件。

语法

ls(选项)(参数)

选项

-a:显示所有档案及目录(ls内定将档案名或目录名称为“.”的视为隐藏,不会列出);
-A:显示除隐藏文件“.”和“..”以外的所有文件列表;
-C:多列显示输出结果。这是默认选项;
-l:与“-C”选项功能相反,所有输出信息用单列格式输出,不输出为多列;
-F:在每个输出项后追加文件的类型标识符,具体含义:“*”表示具有可执行权限的普通文件,“/”表示目录,“@”表示符号链接,“|”表示命令管道FIFO,“=”表示sockets套接字。当文件为普通文件时,不输出任何标识符;
-d:仅显示目录名,而不显示目录下的内容列表。显示符号链接文件本身,而不显示其所指向的目录列表;
-f:此参数的效果和同时指定“aU”参数相同,并关闭“lst”参数的效果;
-i:显示文件索引节点号(inode)。一个索引节点代表一个文件;
--file-type:与“-F”选项的功能相同,但是不显示“*”;
-k:以KB(千字节)为单位显示文件大小;
-l:以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名,文件类型、权限模式、硬连接数、所有者、组、文件大小和文件的最后修改时间等;
-m:用“,”号区隔每个文件和目录的名称;
-n:以用户识别码和群组识别码替代其名称;
-r:以文件名反序排列并输出目录内容列表;
-s:显示文件和目录的大小,以区块为单位;
-t:用文件和目录的更改时间排序;
-L:如果遇到性质为符号链接的文件或目录,直接列出该链接所指向的原始文件或目录;
-R:递归处理,将指定目录下的所有文件及子目录一并处理;
-b:将文件中的不可输出的字符以反斜线“”加字符编码的方式输出;
--full-time:列出完整的日期与时间;
--color[=WHEN]:使用不同的颜色高亮显示不同类型的。

 参数

目录:指定要显示列表的目录,也可以是具体的文件。

实例

显示当前目录下非隐藏文件与目录:

[root@centos6 ~]# ls
anaconda-ks.cfg install.log install.log.syslog

输出长格式列表(文件和文件夹的详细信息):

[root@centos6 ~]# ls -l
total 72
-rw-------. 1 root root 1497 Aug 18 13:34 anaconda-ks.cfg
-rw-r--r--. 1 root root 51437 Aug 18 13:34 install.log
-rw-r--r--. 1 root root 11504 Aug 18 13:31 install.log.syslog

显示当前目录下包括隐藏文件在内的所有文件列表:

[root@centos6 ~]# ls -a
.                .bash_history  .bashrc  .gconf              .tcshrc
..               .bash_logout   .config  install.log         .xauthGBvjmP
anaconda-ks.cfg  .bash_profile  .cshrc   install.log.syslog

显示文件的inode信息:

索引节点(index inode简称为“inode”)是Linux中一个特殊的概念,具有相同的索引节点号的两个文本本质上是同一个文件(除文件名不同外)。

[root@centos6 ~]# ls -i -l anaconda-ks.cfg install.log 
5111817 -rw-------. 1 root root  1497 Aug 18 13:34 anaconda-ks.cfg
5111810 -rw-r--r--. 1 root root 51437 Aug 18 13:34 install.log

水平输出文件列表:

[root@centos6 ~]# ls -m
anaconda-ks.cfg, install.log, install.log.syslog

最近修改的文件显示在最上面:

[root@centos6 ~]# ls -t
anaconda-ks.cfg  install.log  install.log.syslog

打印文件的UID和GID:

[root@centos6 ~]# ls -n
total 72
-rw-------. 1 0 0  1497 Aug 18 13:34 anaconda-ks.cfg
-rw-r--r--. 1 0 0 51437 Aug 18 13:34 install.log
-rw-r--r--. 1 0 0 11504 Aug 18 13:31 install.log.syslog

显示递归文件:

[root@centos6 ~]# ls -R
.:
anaconda-ks.cfg  install.log  install.log.syslog
原文地址:https://www.cnblogs.com/Jimc/p/9512755.html