1.命令功能
ls命令是“list directory contents”,顯示當前目錄下的內容和文件屬性。
2.語法格式
ls [option] file
ls 選項 文件名
3.選項說明
參數 |
參數說明 |
-a |
顯示全部文件包括隱藏文件,包括.和.. |
-A |
顯示全部文件,但是不包括.和..(列出除了”.”和“..”以外的文件) |
-l |
已長文件格式顯示文件屬性 |
-B |
不要列出已~結尾的隱藏文件 |
-F |
在每個文件的末尾添加一個標識符,通過標識符表明該文件的類型。“/”表示目錄,“@”表示符號鏈接,“|”表示FIFOS,“=”表示套接字。 |
-t |
按時間進行文件排序 |
-R |
將目錄下說有的子目錄的文件都列出來。 |
-S |
以文件大小進行排序。 |
說明: linux文件的一些顏色含義:綠色:可執行文件;紅色:壓縮文件;深藍色:目錄;淺藍色:鏈接文件;灰色:其它一些文件。
4. 使用范例
范例1 列出全部文件,包括隱藏文件
[root@localhost cxf]# ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc dir1 dir2 .lesshst test
范例2 列出除了”.”和“..”以外的文件
[root@localhost cxf]# ls -A
.bash_history .bash_logout .bash_profile .bashrc dir1 dir2 .lesshst test
范例3 長格式顯示文件屬性信息
[root@localhost cxf]# ls -l
total 12
drwxr-xr-x. 2 root root 4096 Mar 13 16:43 dir1
drwxr-xr-x. 2 root root 4096 Mar 13 16:43 dir2
-rw-r--r--. 1 root root 12 Mar 13 16:41 test
范例4 在文件尾加上標識符
[root@localhost cxf]# ls -F
dir1/ dir2/ test
[root@localhost cxf]# ls -lF
total 12
drwxr-xr-x. 2 root root 4096 Mar 13 16:43 dir1/
drwxr-xr-x. 2 root root 4096 Mar 13 16:43 dir2/
-rw-r--r--. 1 root root 12 Mar 13 16:41 test
范例5 顯示目錄下的所有子目錄
[root@localhost cxf]# ls -R
.:
dir1 dir2 ok test
./dir1:
./dir2:
./ok:
a
./ok/a:
b
./ok/a/b:
c
./ok/a/b/c: