shell 命令統(tǒng)計(jì)代碼行數(shù)的簡單代碼
分享一個(gè)統(tǒng)計(jì)代碼行的shell命令:
find . “(” -name “.java” -or -name “.html” -or -name “.js” -or -name “.css” “)” -print | xargs wc -l
根據(jù)不同的項(xiàng)目類型,不同的目錄,自行修改。
如果內(nèi)容多,可以:
find . “(” -name “.java” -or -name “.html” -or -name “.js” -or -name “.css” “)” -print | xargs wc -l > statistics.txt
補(bǔ)充:下面看下統(tǒng)計(jì)行數(shù)、字符數(shù)、字節(jié)數(shù)的shell腳本
在linux中,有一個(gè)常用的命令wc,可用來統(tǒng)計(jì)文件的行數(shù)、單詞數(shù)、字符數(shù)以及字節(jié)數(shù)。
運(yùn)行wc命令時(shí),必須明確指定命令中的子文件夾的層級。
通常情況下,用于統(tǒng)計(jì)的文件夾,會(huì)有很多的層級,會(huì)使統(tǒng)計(jì)變得復(fù)雜。
本文提供的這個(gè)腳本,可以幫助我們搜索各級子文件夾,并給出每個(gè)文件夾級別的計(jì)數(shù),并將結(jié)果存儲(chǔ)在一個(gè)單獨(dú)的文件,以供將來使用。
代碼:
代碼示例:
#!/bin/bash #filename: count_lines.sh len=$(echo $1 |awk '{print length($0)}') len2=$(echo $2 |awk '{print length($0)}') if [ $len -ne "0" ] then x="$1" i="1" cc=0 while [ $i -le "$len" ] do echo `expr substr $1 $i 1 ` if [ `expr substr $1 $i 1 ` = "l" ] || [ `expr substr $1 $i 1 ` = "w" ] || [ `expr substr $1 $i 1 ` = "c" ] || [ `expr substr $1 $i 1 ` = "k" ] then lengh = "length=$(echo "$1" |awk '{print length($0)}')" else cc=`expr $cc + 1` fi i=`expr $i + 1` done if [ $cc -eq "0" ] then rm ~/count_output echo "=======================current Directory==========================" >> count_output pwd >> count_output if [ $len2 -eq "0" ] then ls -l * | wc -$1 *.* | tail -k >> ~/count_output else ls -l * | wc -$1 *.$2 | tail -k >> ~/count_output fi ls -R | grep './' > list sed "s/:/ /" list >> list1 cat list1 | while read current_dir do echo "=======================$current_dir ==========================" >> ~/count_output cd $current_dir if [ $len2 -eq "0" ] then ls -l * | wc -$1 *.* | tail -k >> ~/count_output else ls -l * | wc -$1 *.$2 | tail -k >> ~/count_output fi cd - done clear rm list rm list1 else print "invalid entry" fi else print "input options l w c k needs to be entered" fi
總結(jié)
以上所述是小編給大家介紹的shell 命令統(tǒng)計(jì)代碼行數(shù)的簡單代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
利用Linux中的crontab實(shí)現(xiàn)分布式項(xiàng)目定時(shí)任務(wù)功能
crond是Linux用來定期執(zhí)行程序的命令.這篇文章主要介紹了利用Linux中的crontab實(shí)現(xiàn)分布式項(xiàng)目定時(shí)任務(wù),需要的朋友可以參考下2018-01-01Shell中實(shí)現(xiàn)字符串反轉(zhuǎn)方法分享
這篇文章主要介紹了Shell中實(shí)現(xiàn)字符串反轉(zhuǎn)方法分享,本文同時(shí)提供了多種語言的實(shí)現(xiàn)方法,如awk、python、bash、C語言等,需要的朋友可以參考下2014-12-12使用shell腳本采集系統(tǒng)cpu、內(nèi)存、磁盤、網(wǎng)絡(luò)等信息
這篇文章主要介紹了使用shell腳本采集系統(tǒng)cpu、內(nèi)存、磁盤、網(wǎng)絡(luò)等信息,需要的朋友可以參考下2014-05-05Linux shell下30個(gè)有趣的命令和提示(推薦)
這些是我收集了多年的Linux shell的30個(gè)有趣的命令和提示。特此分享到腳本之家平臺(tái),供大家參考2017-10-10shell腳本一鍵部署docker的實(shí)現(xiàn)步驟
作為一名經(jīng)驗(yàn)豐富的開發(fā)者,我們經(jīng)常需要使用Docker來快速部署各種應(yīng)用,本文主要介紹了shell腳本一鍵部署docker的實(shí)現(xiàn)步驟,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03Shell腳本實(shí)現(xiàn)自動(dòng)安裝zookeeper
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)自動(dòng)安裝zookeeper,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-01-01shell學(xué)習(xí)教程獲取命令行參數(shù)示例
這篇文章主要介紹了shell學(xué)習(xí)中的基礎(chǔ)知識(shí)的獲取命令行參數(shù)示例,需要的朋友可以參考下2014-03-03