Linux下統計代碼行數


使用wc統計代碼行數

最近寫了一些代碼,想統計一下代碼的行數,在eclipse中好像沒這功能,網上搜了一下才發現原來Linux有一個統計文件行數的命令wc。使用wc可以打印出每個文件和總文件的行數、字數和字節數,如果沒有指定文件,則會讀取標准輸入(一般是終端)做統計。格式如下:

    Usage: wc [OPTION]... [FILE]...
    -c, --bytes, --chars print the byte counts
    -l, --lines print the newline counts
    -L, --max-line-length print the length of the longest line
    -w, --words print the word counts
        --help display this help and exit
        --version output version information and exit

 

下面舉幾個例子:

1.統計當前目錄下,py文件數量:

  1. find . -name "*.py" |wc -l

2.統計當前目錄下,所有py文件行數:

  1. find . -name "*.py" |xargs cat|wc -l

3.統計當前目錄下,所有py文件行數,並過濾空行:

  1. find . -name "*.py" |xargs cat|grep -v ^$|wc -l
作者:wuyuan 本文來自 Wuyuan's Blog 轉載請注明,謝謝!
文章地址: https://wuyuans.com/2013/07/wc-count-line


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM