Linux ls 命令详解

返回Linux文档目录

ls 命令为英文单词 list 的缩写,正如英文单词 list 的意思,其功能是列出指定目录下的内容及其相关属性信息,下面是该命令的详细使用方式。

用法

ls [参数]  [文件] //如果不指定文件,则以所在目录作为文件

默认情况下 ls 命令会列出当前目录的内容,不过不包括隐藏文件,下面是常用参数

参数 功能
-a 显示所有文件及目录 (包括以“.”开头的隐藏文件)
-l 使用长格式列出文件及目录信息
-r 将文件以相反次序显示(默认依英文字母次序)
-t 根据最后的修改时间排序
-A 同 -a ,但不列出 “.” (当前目录) 及 “..” (父目录)
-S 根据文件大小排序
-R 递归列出所有子目录

如果常用参数不够用,这篇文章里有详细的参数文档:http://linux.51yip.com/search/ls

实例展示

1、列出当前目录的所有文件(不包括隐藏文件)

[root@shuaidi ~]# ls
CS-Book           algo-basic        git_learning      something-learned

2、列出当前目录的所有文件的详细信息列出当前目录的所有文件(不包括隐藏文件)

[root@shuaidi ~]# ls -l
total 0
drwxr-xr-x  10 shuaidi  staff  320  6 13 17:33 CS-Book
drwxr-xr-x  15 shuaidi  staff  480  3 14  2020 algo-basic
drwxr-xr-x   9 shuaidi  staff  288  3 16  2020 git_learning
drwxr-xr-x   7 shuaidi  staff  224  4  6  2020 something-learned

3、列出当前目录的所有文件(包括隐藏文件)

[root@shuaidi ~]# ls -al
total 24
drwxr-xr-x   7 shuaidi  staff    224  3 21  2020 .
drwxr-xr-x   8 shuaidi  staff    256  3  5  2020 ..
-rw-r--r--@  1 shuaidi  staff  10244  3 31 16:52 .DS_Store
drwxr-xr-x  10 shuaidi  staff    320  6 13 17:33 CS-Book
drwxr-xr-x  15 shuaidi  staff    480  3 14  2020 algo-basic
drwxr-xr-x   9 shuaidi  staff    288  3 16  2020 git_learning
drwxr-xr-x   7 shuaidi  staff    224  4  6  2020 something-learned

4、列出根目录下的所有文件(指定文件参数)

[root@shuaidi ~]# ls /
Applications              cores                     private
Library                   dev                       sbin
Network                   etc                       tmp
System                    home                      usr
Users                     installer.failurerequests var
Volumes                   net                       vm
bin                       opt

5、列出当前工作目录下所有文件及目录并以文件的大小进行排序 :

[root@shuaidi ~]# ls -lS
total 0
drwxr-xr-x  15 shuaidi  staff  480  3 14  2020 algo-basic
drwxr-xr-x  10 shuaidi  staff  320  6 13 17:33 CS-Book
drwxr-xr-x   9 shuaidi  staff  288  3 16  2020 git_learning
drwxr-xr-x   7 shuaidi  staff  224  4  6  2020 something-learned

更多的命令及其案例,可以自己尝试哦,大家最主要的就是要大致知道 ls 能干嘛,至于具体的参数,忘记了没事,知道它有这个功能就行了,之后需要的时候,快速打开文档查看即可。

发表评论

后才能评论