[精讚] [會員登入]
6827

計算檔案數和目錄數

linux/freebsd等系統利用ls來計算檔案數和目錄數、只列出目錄的方法

分享此文連結 //n.sfs.tw/10752

分享連結 計算檔案數和目錄數@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2019-10-25 10:57:56 最後編修
2017-02-08 22:44:59 By 張○○
 

自動目錄

計算檔案數

$ ls -l  |grep "^-"|wc -l

計算目錄數

$ ls -l  |grep "^d"|wc -l

只列出目錄

$ ls -F | grep /$
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/

或者使用下面的方式:

$ ls -l --color | grep "^d"

參考資料

[1] 程式扎記  http://puremonkey2010.blogspot.com/2010/11/linux-m-find.html


原文 2010-12-16 11:02:55

END

你可能感興趣的文章

利用tr如何移除檔案中的 ^M 利用tr如何移除檔案中的換行 ^M

[find] 活用 find 指令參數-atime -Btime -ctime -mtime 限制尋找時間 活用 find 指令參數-atime -Btime -ctime -mtime 限制尋找時間

[Linux] ls --color 的檔案特徵及顏色意義 ls --color 時看到的檔案特徵及顏色意義及和檔案權限有關的指令

[find] 活用 find 指令參數-exec 執行找到的結果 在linux/ freebsd 中查找檔案最強的就是 find,他有一個參數相當好用:-exec

[Linux] mongodb 初步--3/3 我使用mongo 的一些大小事:資料庫的權限、幫助

[CSH/TCSH] 使用tcsh SHELL #1 --變數、控制和迴圈 在FREEBSD或LINUX中使用TCSH SHELL,進行一些基本的指令操作。

隨機好文

[jQuery] select 元件的取值及給值 html中的元件select,在jquery中要如何使用?

[CodeIgniter 3] 資料庫的使用方法整理2/2 CI3 承襲 CI2,有很多的builder class可以用,依各人的使用習慣,有人喜歡一堆sql字串,有人喜歡用helper

[Wildfly10] 發佈war檔 deploy war file onto wildfly10

[AS3] 變數型態 基本類型宣告 as3 有下列幾種基本類型:string, int, number, object, boolean, n

[MySQL/Mariadb] console 將查詢結果輸出到檔案 在mysql 的console中該如何將查詢結果輸出到檔案?