1、find 和xargs命令结合
$find . -type f -name "*.c" -o -name "*.h" | xargs wc -l
8 ./A.c
8 ./a.c
16 total
2、wc直接统计
$wc -l $(find . -type f -name "*.c" -o -name "*.h")
8 ./A.c
8 ./a.c
16 total
本文介绍了两种统计C源代码行数的方法:一种是使用find命令配合xargs调用wc命令来统计,另一种是直接使用wc命令配合find命令进行统计。这两种方法均可有效地帮助开发者快速了解项目规模。
1、find 和xargs命令结合
$find . -type f -name "*.c" -o -name "*.h" | xargs wc -l
8 ./A.c
8 ./a.c
16 total
2、wc直接统计
$wc -l $(find . -type f -name "*.c" -o -name "*.h")
8 ./A.c
8 ./a.c
16 total
6708