計算檔案數
$ ls -l |grep "^-"|wc -l
計算目錄數
$ ls -l |grep "^d"|wc -l
只列出目錄
$ ls -F | grep /$
auth/
common/
content/
errors/
index/
manage/
auth/
common/
content/
errors/
index/
manage/
上面的-F參數是列出的目錄後面會帶有一個斜線,再用grep抓取。grep /$意思是抓取最後一個是斜線的行
但這樣子缺點會是會沒有顏色,同時只有一行,因此加上 --color:
$ ls -Fl --color |grep /$
drwxr-xr-x. 2 root root 4096 2016-11-26 22:58 auth/
drwxr-xr-x. 2 root root 4096 2016-12-05 04:35 common/
drwxr-xr-x. 2 root root 4096 2017-02-08 21:34 content/
drwxr-xr-x. 4 root root 4096 2016-09-23 12:15 errors/
drwxr-xr-x. 2 root root 4096 2017-02-06 03:06 index/
drwxr-xr-x. 2 root root 4096 2017-01-26 22:17 manage/
drwxr-xr-x. 2 root root 4096 2016-11-26 22:58 auth/
drwxr-xr-x. 2 root root 4096 2016-12-05 04:35 common/
drwxr-xr-x. 2 root root 4096 2017-02-08 21:34 content/
drwxr-xr-x. 4 root root 4096 2016-09-23 12:15 errors/
drwxr-xr-x. 2 root root 4096 2017-02-06 03:06 index/
drwxr-xr-x. 2 root root 4096 2017-01-26 22:17 manage/
或者使用下面的方式:
$ ls -l --color | grep "^d"
參考資料
[1] 程式扎記 http://puremonkey2010.blogspot.com/2010/11/linux-m-find.html
原文 2010-12-16 11:02:55