ls是最常被应用到的Linux命令之一,它来自英语单词list的缩写,就像list单词的英语意思一样。它的性能是列出指定目录下的文件名称和特色。

默认状况下不增加参数,ls指令将列出各种工作目录中的文件信息,通常与cd和pwd配合应用指令十分不便。带上参数后,咱们能够做更多的事件。

作为最根本、最罕用的命令,有必要认真理解其罕用性能。


本次测试环境:Centos7.6零碎-服务器来自:  蓝易云

定位建站服务器,特点是 香港五网CN2网络 ,国内速度优良,反对VPC内网互联、快照、备份等性能。

挪动+联通+电信+教育网+广电-五网CN2-提早超低!

蓝易云持有 IDC 、 ISP 、CDN许可证,为正规商家。


语法格局: ls [参数] [文件]

罕用参数:

-a显示所有文件及目录 (包含以“.”结尾的暗藏文件)
-l应用长格局列出文件及目录的详细信息
-r将文件以相同秩序显示(默认依英文字母秩序)
-t依据最初的批改工夫排序
-A同 -a ,但不列出 “.” (当前目录) 及 “..” (父目录)
-S依据文件大小排序
-R递归列出所有子目录
-d查看目录的信息,而不是外面子文件的信息
-i输入文件的inode节点信息
-m程度列出文件,以逗号距离
-X按文件扩展名排序
--color输入信息中带有着色成果

参考实例

输入当前目录中的文件(默认不含暗藏文件):

[root@linuxcool ~]# lsanaconda-ks.cfg  Documents  initial-setup-ks.cfg  Pictures  TemplatesDesktop          Downloads  Music                 Public    Videos

输入当前目录中的文件(含暗藏文件):

[root@linuxcool ~]# ls -a.                .bashrc  Documents             Music      Videos..               .cache   Downloads             Pictures   .viminfoanaconda-ks.cfg  .config  .esd_auth             .pki.bash_history    .cshrc   .ICEauthority         Public.bash_logout     .dbus    initial-setup-ks.cfg  .tcshrc.bash_profile    Desktop  .local                Templates

输入文件的长格局,蕴含属性详情信息:

[root@linuxcool ~]# ls -ltotal 8-rw-------. 1 root root 1430 Dec 14 08:05 anaconda-ks.cfgdrwxr-xr-x. 2 root root    6 Dec 14 08:37 Desktopdrwxr-xr-x. 2 root root    6 Dec 14 08:37 Documentsdrwxr-xr-x. 2 root root    6 Dec 14 08:37 Downloads-rw-r--r--. 1 root root 1585 Dec 14 08:34 initial-setup-ks.cfgdrwxr-xr-x. 2 root root    6 Dec 14 08:37 Musicdrwxr-xr-x. 2 root root    6 Dec 14 08:37 Picturesdrwxr-xr-x. 2 root root    6 Dec 14 08:37 Publicdrwxr-xr-x. 2 root root    6 Dec 14 08:37 Templatesdrwxr-xr-x. 2 root root    6 Dec 14 08:37 Videos

输入指定目录中的文件列表:

[root@linuxcool ~]# ls /etcadjtime                     hosts                     pulsealiases                     hosts.allow               qemu-gaalsa                        hosts.deny                qemu-kvmalternatives                hp                        radvd.confanacrontab                  idmapd.conf               rasasound.conf                 init.d                    rc0.dat.deny                     inittab                   rc1.d………………省略局部输入信息………………

输入文件名称及inode属性块号码:

[root@linuxcool ~]# ls -i35290115 anaconda-ks.cfg  35290137 initial-setup-ks.cfg  35290164 Templates 1137391 Desktop          17840039 Music                 51609597 Videos 1137392 Documents        35290165 Pictures17840038 Downloads        51609596 Public

搭配通配符一起应用,输入指定目录中所有以sd结尾的文件名称:

[root@linuxcool ~]# ls /dev/sd*/dev/sda  /dev/sda1  /dev/sda2

根据文件大小进行排序,输入指定目录中文件属性详情信息:

[root@linuxcool ~]# ls -Sl /etctotal 1348-rw-r--r--.  1 root root    692241 Sep 10  2018 services-rw-r--r--.  1 root root     66482 Dec 14 08:34 ld.so.cache-rw-r--r--.  1 root root     60352 May 11  2017 mime.types-rw-r--r--.  1 root dnsmasq  26843 Aug 12  2018 dnsmasq.conf-rw-r--r--.  1 root root     25696 Dec 12  2018 brltty.conf-rw-r--r--.  1 root root      9450 Aug 12  2018 nanorc-rw-r--r--.  1 root root      7265 Dec 14 08:03 kdump.conf-rw-------.  1 tss  tss       7046 Aug 13  2018 tcsd.conf………………省略局部输入信息………………