1. 程式人生 > >Linux 檢視某資料夾下檔案數量

Linux 檢視某資料夾下檔案數量

轉至:www.xitongzhijia.net/xtjc/20150504/47340.html

LInux  find指令的使用:

  find命令檢視(推薦):

  所有子目錄的數量:

  [[email protected] ~]# find pma -type d | wc -l

  125

  [[email protected] ~]# find pma/ -type d | wc -l

  125

  [[email protected] ~]# find pma/* -type d | wc -l

  124 --正確

  結果不同的原因:

  [

[email protected] ~]# find pma -type d | more

  pma --輸出結果首行

  [[email protected] ~]# find pma/* -type d | more

  pma/examples --輸出結果首行

  總結:使用pma/*不包含pma這個父目錄,只輸出其下的子目錄。

  所有檔案的數量:

  [[email protected] ~]# find pma -type f | wc -l

  987

  [[email protected] ~]# find pma/ -type f | wc -l

  987

  [[email protected] ~]# find pma/* -type f | wc -l

  987

  tree命令檢視(不推薦):

  [[email protected] ~]# tree pma

  ……

  124 directories, 984 files

  -----------------------------------------

  [[email protected] ~]# tree pma/

  ……

  124 directories, 984 files

  du命令檢視:

  [[email protected]

~]# du -ah pma/* | wc -l

  1111

  總結:du檢視的結果為1111,子目錄的數量為124,檔案數量為:1111-124=987,所以tree命令檢視的結果應該是不準確,至於少計算了哪個檔案,沒再查這個問題,推薦使用find命令檢視。

  以上就是兩種檢視子資料夾及檔案的數量的方法,如上述所說,小編認為還是使用find命令顯示檢視會相對準確些。如果友友們還有更為簡便的方法,歡迎與小編留言互動哦。