关于运维:Linux系统-ls命令-–-显示指定工作目录下的文件及属性信息

4次阅读

共计 2318 个字符,预计需要花费 6 分钟才能阅读完成。

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

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

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


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

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

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

蓝易云持有 IDCISPCDN 许可证,为正规商家。


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

罕用参数:

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

参考实例

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

[root@linuxcool ~]# ls
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Pictures  Templates
Desktop          Downloads  Music                 Public    Videos

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

[root@linuxcool ~]# ls -a
.                .bashrc  Documents             Music      Videos
..               .cache   Downloads             Pictures   .viminfo
anaconda-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 -l
total 8
-rw-------. 1 root root 1430 Dec 14 08:05 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Dec 14 08:37 Desktop
drwxr-xr-x. 2 root root    6 Dec 14 08:37 Documents
drwxr-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.cfg
drwxr-xr-x. 2 root root    6 Dec 14 08:37 Music
drwxr-xr-x. 2 root root    6 Dec 14 08:37 Pictures
drwxr-xr-x. 2 root root    6 Dec 14 08:37 Public
drwxr-xr-x. 2 root root    6 Dec 14 08:37 Templates
drwxr-xr-x. 2 root root    6 Dec 14 08:37 Videos

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

[root@linuxcool ~]# ls /etc
adjtime                     hosts                     pulse
aliases                     hosts.allow               qemu-ga
alsa                        hosts.deny                qemu-kvm
alternatives                hp                        radvd.conf
anacrontab                  idmapd.conf               ras
asound.conf                 init.d                    rc0.d
at.deny                     inittab                   rc1.d
………………省略局部输入信息………………

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

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

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

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

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

[root@linuxcool ~]# ls -Sl /etc
total 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
………………省略局部输入信息………………
正文完
 0