Total number of lines in a directory

后端 未结 7 2086
礼貌的吻别
礼貌的吻别 2021-01-13 08:52

I have a directory with thousands of files (100K for now). When I use wc -l ./*, I\'ll get:

 c1            ./test1.txt
 c2            ./tes         


        
7条回答
  •  感动是毒
    2021-01-13 09:29

    awk 'END {print NR" total"}' ./*
    

    Would be an interesting comparison to find out how many lines don’t end with a new line.

    Combining the awk and Gordon’s find solutions and avoiding the “.” files.

    find ./* -maxdepth 0 -type f -exec awk ‘END {print NR}’ {} +
    

    No idea if this is better or worse but it does give a more accurate count (for me) and does not count lines in “.” files. Using ./* is just a guess that appears to work.

    Still need depth and ./* requires “0” depth.

    I did get the same result with the “cat” and “awk” solutions (using the same find) since the “cat *” takes care of the new line issue. I don’t have a directory with enough files to measure time. Interesting, I’m liking the “cat” solution.

提交回复
热议问题