天天看點

《懶人Shell腳本》之十——統計多重路徑下的不同擴充名檔案及個數

1、統計實作

find -type f | sed -e 's/.*\.//' | sort | uniq -c | sort -n > rst.txt           

2、腳本分解

1) find -type f

regular file , 查找正規的檔案

傳回:./bak_network/道x網站/bak_第8章.md

b block (buffered) special
 c character (unbuffered) special
 d directory
 p named pipe (FIFO)
 f regular file
 l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for
 symbolic links when -L is in effect, use -xtype.
 s socket
D door (Solaris)           

2) sed -e ‘s/.*.//’

任意字元到. 替換為 空,即取得字尾名           

3) sort

排序           

4) uniq -c

-c, –count 
prefix lines by the number of occurrences 
第一列統計對應的行數           

5) sort -n

compare according to string numerical value

以數字列排序

排序結果為:

1 docx
  2 jar
  2 part
  4 xlsx
  5 rar
  6 PDF
  17 xls
  122 doc
  149 zip
  322 json
  21305 pdf
  154981 jpg
  1559454 txt
 3029912 html           

作者:銘毅天下

轉載請标明出處,原文位址:

http://blog.csdn.net/laoyang360/article/details/77860110