ls命令
-
功能說明:列出指定目錄下的檔案串列(包括子目錄),但不能顯示檔案內容
-
用 法:ls [OPTION]... [FILE]...
選項 作用 -a 顯示所有檔案,包括隱藏檔案 -A 顯示除.和..之外的所有檔案 -l 顯示檔案的詳細屬性資訊 -h 對檔案大小做單位換算,以人類可讀的方式顯示,換算后的結果非精確值 -d 查看目錄本身而非其內部的檔案串列,通常-l和-d結合起來使用, -r 逆序顯示 -R 遞回顯示,如果目錄中還有檔案,它會把目錄中的檔案也列印出來
示例1: 顯示當前目錄下的所有檔案,包括隱藏檔案,
[root@node1 ~]# ls -a
. anaconda-ks.cfg .bash_history .bash_profile .cache .cshrc .viminfo
.. a.sh .bash_logout .bashrc .config .tcshrc
示例2:顯示當前目錄下除.和..之外的所有檔案,
[root@node1 ~]# ls -A
anaconda-ks.cfg .bash_history .bash_profile .cache .cshrc .viminfo
a.sh .bash_logout .bashrc .config .tcshrc
示例3:ls命令不帶任何引數,則顯示當前目錄下的內容,
[root@node1 ~]# ls
anaconda-ks.cfg a.sh
示例4:ls命令跟路徑,顯示指定路徑下內容,
[root@node1 ~]# ls /var/
adm cache crash db empty ftp games gopher kerberos lib local lock log mail nis opt preserve run spool tmp yp
示例5:ls命令使用-l選項,顯示檔案的詳細屬性資訊,
[root@node1 ~]# ls -l
total 68
-rw-------. 1 root root 1652 Jul 25 19:40 anaconda-ks.cfg
-rw-r--r--. 1 root root 48866 Jul 25 19:40 install.log
-rw-r--r--. 1 root root 9451 Jul 25 19:37 install.log.syslog
...

檔案型別:
| 符號 | 代表意義 |
|---|---|
| - | 普通檔案(file) |
| d | 目錄檔案(directory) |
| b | 塊設備檔案(block) |
| c | 字符設備檔案(character) |
| l | 符號鏈接檔案(symbolic link file) |
| p | 命令管道檔案(pipe) |
| s | 套接字檔案(socket) |
示例6:ls命令使用-h選項對檔案大小做單位換算,以人類可讀的方式顯示,換算后的結果非精確值,
[root@node1 ~]# ls -lh
total 68K
-rw-------. 1 root root 1.7K Jul 25 19:40 anaconda-ks.cfg
-rw-r--r--. 1 root root 48K Jul 25 19:40 install.log
-rw-r--r--. 1 root root 9.3K Jul 25 19:37 install.log.syslog
...
示例7:ls命令使用-ld選項查看目錄自身的屬性,而非其內部的檔案串列的屬性,通常-l和-d結合起來使用,
[root@node1 ~]# ls -ld /var/log/
drwxr-xr-x. 8 root root 4096 May 28 11:21 /var/log/
示例8:ls命令使用-r選項逆序顯示當前目錄中的內容,
[root@www ~]# mkdir /tmp/test
[root@www ~]# cd /tmp/test/
[root@www test]# mkdir {a..f}
[root@www test]# ls -l
total 0
drwxr-xr-x 2 root root 6 Apr 8 03:53 a
drwxr-xr-x 2 root root 6 Apr 8 03:53 b
drwxr-xr-x 2 root root 6 Apr 8 03:53 c
drwxr-xr-x 2 root root 6 Apr 8 03:53 d
drwxr-xr-x 2 root root 6 Apr 8 03:53 e
drwxr-xr-x 2 root root 6 Apr 8 03:53 f
[root@www test]# ls -lr
total 0
drwxr-xr-x 2 root root 6 Apr 8 03:53 f
drwxr-xr-x 2 root root 6 Apr 8 03:53 e
drwxr-xr-x 2 root root 6 Apr 8 03:53 d
drwxr-xr-x 2 root root 6 Apr 8 03:53 c
drwxr-xr-x 2 root root 6 Apr 8 03:53 b
drwxr-xr-x 2 root root 6 Apr 8 03:53 a
示例9:ls命令使用-R選項遞回顯示,如果目錄中還有檔案,它會把目錄中的檔案也列印出來,
[root@www test]# cd a
[root@www a]# mkdir {a..d}
[root@www a]# cd ..
[root@www test]# ls -lR
.:
total 0
drwxr-xr-x 6 root root 38 Apr 8 03:56 a
drwxr-xr-x 2 root root 6 Apr 8 03:53 b
drwxr-xr-x 2 root root 6 Apr 8 03:53 c
drwxr-xr-x 2 root root 6 Apr 8 03:53 d
drwxr-xr-x 2 root root 6 Apr 8 03:53 e
drwxr-xr-x 2 root root 6 Apr 8 03:53 f
./a:
total 0
drwxr-xr-x 2 root root 6 Apr 8 03:56 a
drwxr-xr-x 2 root root 6 Apr 8 03:56 b
drwxr-xr-x 2 root root 6 Apr 8 03:56 c
drwxr-xr-x 2 root root 6 Apr 8 03:56 d
./a/a:
total 0
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/69087.html
標籤:Linux
上一篇:上古神器vim系列之移動三板斧
