虚位以待(AD)
虚位以待(AD)
首页 > 脚本专栏 > linux shell > shell 命令统计代码行数的简单代码

shell 命令统计代码行数的简单代码
类别:linux shell   作者:码皇   来源:互联网   点击:

这篇文章主要介绍了shell 命令统计代码行数的简单代码,文中给大家提到了统计行数、字符数、字节数的shell脚本,需要的朋友可以参考下

分享一个统计代码行的shell命令:

    find . “(” -name “.java” -or -name “.html” -or -name “.js” -or -name “.css” “)” -print | xargs wc -l

根据不同的项目类型,不同的目录,自行修改。

如果内容多,可以:

    find . “(” -name “.java” -or -name “.html” -or -name “.js” -or -name “.css” “)” -print | xargs wc -l > statistics.txt

补充:下面看下统计行数、字符数、字节数的shell脚本

在linux中,有一个常用的命令wc,可用来统计文件的行数、单词数、字符数以及字节数。

运行wc命令时,必须明确指定命令中的子文件夹的层级。

通常情况下,用于统计的文件夹,会有很多的层级,会使统计变得复杂。

本文提供的这个脚本,可以帮助我们搜索各级子文件夹,并给出每个文件夹级别的计数,并将结果存储在一个单独的文件,以供将来使用。

代码:

代码示例:

    #!/bin/bash#filename: count_lines.shlen=$(echo $1 |awk '{
    print length($0)}
    ')len2=$(echo $2 |awk '{
    print length($0)}
    ')if [ $len -ne "0" ]thenx="$1"i="1"cc=0while [ $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`doneif [ $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 list1else print "invalid entry"fielseprint "input options l w c k needs to be entered"fi

总结

以上所述是小编给大家介绍的shell 命令统计代码行数的简单代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

您可能感兴趣的文章:

  • Shell脚本实现C语言代码行数统计
  • shell判断文件是否为空的代码
  • shell脚本 自动创建用户详解及实例代码
  • shell脚本实现同时多台远程主机执行命令的代码分享
  • PowerShell连接SQL SERVER数据库进行操作的实现代码
  • Powershell 之批量获取文件大小的实现代码
相关热词搜索: shell 统计代码 shell 代码行数