递归遍历文件夹统计文件的行数

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

#!/usr/bin/perl
$pwd="/home/program/";
$wc_temp="$pwd/wc_temp";
sub sum{
    my @file=<*>;
    foreach(@file){
	#print "$_\n";
	chomp;
	my $path=`pwd`;
	chomp $path;
	if(-d){
	    chdir "$_" or die "con't chdir\n";
	    #print "$path\n";
	    &sum;
	    chdir "$path" or die "con't chdir\n";
	}elsif(-s){ #文件大小大于0
	    $total++;
	    if($_ eq "wc.file"){
		next;
	    }
	    $ENV{"tt"}=$_; #改变shell环境变量
	    $ENV{wc_temp}=$wc_temp;
	    system 'wc $tt >> $wc_temp';
	   # print "$_\n";
	}
    }
}
&sum;
chdir "$pwd" or die "con't chdi\n";
system 'sort -n $wc_temp >wc.file'; #记录所有程序的代码行数
unlink "$wc_temp";
open FIN,"wc.file" or die "con't open$!";
foreach(<FIN>){
    chomp;
    @line=split;
    $num+=$line[0];
}
print "total_file=$total\n";
print "line=$num\n";