1. 程式人生 > >使用wc統計代碼行數

使用wc統計代碼行數

... 當前 linu class 統計文件行數 代碼 fin pri cli

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

  1. Usage: wc [OPTION]... [FILE]...
  2. -c, --bytes, --chars print the byte counts
  3. -l, --lines print the newline counts
  4. -L, --max-line-length print the length of the longest line
  5. -w, --words print the word counts
  6. --help display this help and exit
  7. --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

使用wc統計代碼行數