写点什么

【文件管理】Linux 系统 -ls 命令 – 显示指定工作目录下的文件及属性信息

  • 2023-07-08
    四川
  • 本文字数:1562 字

    阅读完需:约 5 分钟

【文件管理】Linux系统-ls命令 – 显示指定工作目录下的文件及属性信息

ls 是最常被使用到的 Linux 命令之一,来自于英文单词 list 的缩写,也正如 list 单词的英文意思,其功能是列举出指定目录下的文件名称及其属性。


默认不加参数的情况下,ls 命令会列出当前工作目录中的文件信息,经常与 cd 和 pwd 命令搭配使用,十分方便。而带上参数后,我们则可以做更多的事情,作为最基础、最频繁使用的命令,有必要仔细了解下其常用功能。


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


常用参数:




参考实例


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


[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………………省略部分输出信息………………
复制代码


用户头像

还未添加个人签名 2023-07-05 加入

还未添加个人简介

评论

发布
暂无评论
【文件管理】Linux系统-ls命令 – 显示指定工作目录下的文件及属性信息_Linux_百度搜索:蓝易云_InfoQ写作社区