ls詳解
羅列目錄內容權限,列出文件的信息列表(默認為當前目錄)。
這個命令是Linux操作系統使用頻率最高的命令,沒有之一。熟練掌握這個命令的常用參數,可以提高學習、工作效率,因此需要認真對待。
1. 常用選項
– -a,–all:顯示當前目錄下全部文件(常用)
[root@jingz ~]# ls -a ..bash_history .bashrc .cshrc.lesshst .viminfo .xauthVB71h5.. .bash_logout .cache .dbus .local.xauth3F8Xbp anaconda-ks.cfg .bash_profile .config initial-setup-ks.cfg .tcshrc .xauth3fbnpT
-A, –almost-all:顯示當前目錄下的所有文件但是不包括.和..這兩個目錄
[root@jingz ~]# ls -A anaconda-ks.cfg .bash_profile .config initial-setup-ks.cfg .tcshrc .xauth3fbnpT .bash_history .bashrc .cshrc .lesshst .viminfo .xauthVB71h5 .bash_logout .cache .dbus .local .xauth3F8Xbp
-l: 用長格式顯示非隱藏文件,列出長數數據串,包含文件的屬性與權限等(常用)
[root@jingz ~]# ls -l total 8 -rw-------. 1 root root 1706 Jul 24 18:31 anaconda-ks.cfg -rw-------. 1 root root 1754 Jul 24 09:56 initial-setup-ks.cfg
–author:和-l選項一起使用,顯示出每個文件的作者
[root@jingz ~]# ls -l --author total 8 -rw-------. 1 root root root 1706 Jul 24 18:31 anaconda-ks.cfg -rw-------. 1 root root root 1754 Jul 24 09:56 initial-setup-ks.cfg
-d, –directory:僅僅列出目錄本身,而不列出目錄內的文件數據(常用)
[root@jingz ~]# ls -d /etc /etc
-f :直接列出結果,而不進行排序(ls 默認以文件名排序)
-F :根據文件、目錄等信息給予附加數據結構,例如: * 代表可執行文件; / 代表目錄; = 代表 socket文件;| 代表 FIFO文件
[root@jingz ~]# ls -F / bin@ dev/ home/ lib64@ mnt/ proc/ run/ srv/ testdir/ usr/ boot/ etc/ lib@ media/ opt/ root/ sbin@ sys/ tmp/ var/
這個命令現在用的不多因為現在有了顏色高亮,可以通過不同顏色來判斷目錄,文件等等;
藍色文件———-目錄
白色文件———-一般性文件,如文本文件,配置文件,源碼文件等
淺藍色文件———-鏈接文件,主要是使用ln命令建立的文件
綠色文件———-可執行文件,可執行的程序
紅色文件———–壓縮文件或者包文件
-h ,將文件容量以人類易讀的方式(例如GB,KB等)列出來(常用)
[root@jingz ~]# ls -hl total 12K -rw-r--r--. 1 root root 54 Jul 30 17:23 123 -rw-------. 1 root root 1.7K Jul 24 18:31 anaconda-ks.cfg -rw-------. 1 root root 1.8K Jul 24 09:56 initial-setup-ks.cfg
-i ,列出inode號碼(常用)
[root@jingz ~]# ls -i 104432133 123 104922027 anaconda-ks.cfg 104428540 initial-setup-ks.cfg
-n 列出UID和GID
[root@jingz ~]# ls -n total 12 -rw-r--r--. 1 0 0 54 Jul 30 17:23 123 -rw-------. 1 0 0 1706 Jul 24 18:31 anaconda-ks.cfg -rw-------. 1 0 0 1754 Jul 24 09:56 initial-setup-ks.cfg
–full-time 以完整時間模式(包含年、月、日、時、分、秒)輸出
[root@jingz ~]# ls --full-time total 12 -rw-r--r--. 1 root root 54 2016-07-30 17:23:01.531177259 +0800 123 -rw-------. 1 root root 1706 2016-07-24 18:31:24.384061072 +0800 anaconda-ks.cfg -rw-------. 1 root root 1754 2016-07-24 09:56:04.952024819 +0800 initial-setup-ks.cfg
-r 將結果反向輸出,例如原來是由大到小,現在就由小到大
-R 連同子目錄下面的所有非隱藏文件都顯示出來
-S 以文件容量大小排序,而不用文件名排序
-t –time=(ctime|atime)按照時間排序,而不是文件名
2. 常用組合
ll 是一個別名,是代表ls -l的意思
[root@jingz ~]# ll total 12 -rw-r--r--. 1 root root 54 Jul 30 17:23 123 -rw-------. 1 root root 1706 Jul 24 18:31 anaconda-ks.cfg -rw-------. 1 root root 1754 Jul 24 09:56 initial-setup-ks.cfg
ls -ld 顯示當前目錄的詳細信息
[root@jingz ~]# ll -d dr-xr-x---. 6 root root 4096 Jul 30 17:23 .
ls -al 列出當前目錄的所有文件的詳細信息
[root@jingz ~]# ls -al total 76 dr-xr-x---. 6 root root 4096 Jul 30 17:23 . dr-xr-xr-x. 18 root root 4096 Jul 27 11:13 .. -rw-r--r--. 1 root root 54 Jul 30 17:23 123 -rw-------. 1 root root 1706 Jul 24 18:31 anaconda-ks.cfg -rw-------. 1 root root 10329 Jul 30 18:32 .bash_history
ls -al –full-time :列出當前文件所有的詳細信息及準確時間
[root@jingz ~]# ls --full-time -al total 76 dr-xr-x---. 6 root root 4096 2016-07-30 17:23:01.518177258 +0800 . dr-xr-xr-x. 18 root root 4096 2016-07-27 11:13:51.466531634 +0800 .. -rw-r--r--. 1 root root 54 2016-07-30 17:23:01.531177259 +0800 123 -rw-------. 1 root root 1706 2016-07-24 18:31:24.384061072 +0800 anaconda-ks.cfg -rw-------. 1 root root 10329 2016-07-30 18:32:56.663329844 +0800 .bash_history
ll -ahS 用人類可讀的格式由大到小列出所有文件
[root@jingz ~]# ll -aSh total 76 total 76K -rw-------. 1 root root 11K Jul 30 18:32 .bash_history -rw-------. 1 root root 4.8K Jul 30 11:10 .viminfo
原創文章,作者:fighter,如若轉載,請注明出處:http://www.www58058.com/26924