请注意,本文编写于 711 天前,最后修改于 631 天前,其中某些信息可能已经过时。
ls 是 list 的缩写,ls命令用来列出指定目录下的全部文件和文件夹。
语法:
ls [选项] [目录名/文件名]
选项:
-l :除文件名称外,亦将文件型态、权限、拥有者、文件大小等资讯详细列出
-a :-all 列出全部的文件和目录,包括隐藏的文件和目录(以"."开头的文件和目录)和".(表示当前目录)"以及"..(表示当前目录的父目录)"
...
# 更多的选项可以用 ls --help 来查看。
实例:
# 实例一:默认用法
[email protected]:~# ls test
test test.txt
# 实例二:以列表的形式列出
[email protected]:~# ls -l test
total 4
drwxr-xr-x 2 root root 4096 7月 9 07:47 test
-rw-r--r-- 1 root root 0 7月 9 07:47 test.txt
# 实例三:显示隐藏的文件和文件夹(.开头的文件或文件夹默认隐藏,如.test2和.test2.txt)
[email protected]:~# ls -a test
. .. test .test2 .test2.txt test.txt
# 实例五:显示隐藏的文件和文件夹,并以列表的形式列出(ls -alF 等同于 ll)
[email protected]:~/test# ls -al
总用量 20
drwxrwxrwx 5 root root 4096 7月 10 19:25 .
drwx------ 15 root root 4096 7月 9 23:11 ..
drwxr-xr-x 2 root root 4096 7月 10 19:25 .test
drwxrwxrwx 2 root root 4096 7月 9 22:23 test2
-rwxrwxrwx 1 root root 0 7月 9 21:47 test2.txt
drwxrwxrwx 5 root root 4096 7月 9 22:31 test3
-rwxrwxrwx 1 root root 0 7月 9 21:47 test3.txt
-rw-r--r-- 1 root root 0 7月 10 19:24 .test.txt
# 实例六:显示指定文件的详细信息
[email protected]:~/test# ls -l test2.txt
-rwxrwxrwx 1 root root 0 7月 9 21:47 test2.txt