Linux 下使用 wc 统计文件夹下所有文件的代码行数(包括子目录)
2015-02-25 18:43
1631 查看
wc 命令用于统计文件内容的行数、单词数、字母数。
但是如果想统计一个目录下所有文件的行数,wc 并没有提供递归统计。
不过,可以结合 find 命令,例如:
$ wc -l `find -name *.c`
其中,-l 参数是统计行数,find -name *.c 是查找当前目录(包含子目录)下所有的C文件,` `
是 shell 中的替换命令。
当然,实现方法有很多,我只是觉得这个比较简单易记。
测试效果如下:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202012/03/60db263e3f99fe171b7c3bcce342fbb0)
最后,附一下 wc 的使用帮助(man wc)
NAME
wc - print newline, word, and byte counts for each file
SYNOPSIS
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
DESCRIPTION
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input. A word is a non-zero-length sequence
of characters delimited by white space. The options below may be used to select which counts are printed, always in the following order: newline, word, character, byte, maximum line length.
-c, --bytes
print the byte counts
-m, --chars
print the character counts
-l, --lines
print the newline counts
--files0-from=F
read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input
-L, --max-line-length
print the length of the longest line
-w, --words
print the word counts
--help display this help and exit
--version
output version information and exit
但是如果想统计一个目录下所有文件的行数,wc 并没有提供递归统计。
不过,可以结合 find 命令,例如:
$ wc -l `find -name *.c`
其中,-l 参数是统计行数,find -name *.c 是查找当前目录(包含子目录)下所有的C文件,` `
是 shell 中的替换命令。
当然,实现方法有很多,我只是觉得这个比较简单易记。
测试效果如下:
最后,附一下 wc 的使用帮助(man wc)
NAME
wc - print newline, word, and byte counts for each file
SYNOPSIS
wc [OPTION]... [FILE]...
wc [OPTION]... --files0-from=F
DESCRIPTION
Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. With no FILE, or when FILE is -, read standard input. A word is a non-zero-length sequence
of characters delimited by white space. The options below may be used to select which counts are printed, always in the following order: newline, word, character, byte, maximum line length.
-c, --bytes
print the byte counts
-m, --chars
print the character counts
-l, --lines
print the newline counts
--files0-from=F
read input from the files specified by NUL-terminated names in file F; If F is - then read names from standard input
-L, --max-line-length
print the length of the longest line
-w, --words
print the word counts
--help display this help and exit
--version
output version information and exit
相关文章推荐
- du 使用详解 linux查看目录大小 linux统计目录大小并排序 查看目录下所有一级子目录文件夹大小 du -h --max-depth=1 |grep [ 发
- linux下shell统计文件目录下所有代码行数
- du 使用详解 linux查看目录大小 linux统计目录大小并排序 查看目录下所有一级子目录文件夹大小 du -h --max-depth=1 |grep [
- Linux 下wc 统计递归统计目录及其子目录下文件的行数
- C++ 一个统计文件夹下所有代码文件行数的小工具
- linux 使用wc命令统计文件行数、字数及大小
- 在linux下使用wc来统计文件行数
- Linux列出某文件夹下面所有文件包括子目录得的文件
- 利用正则表达式统计某个某个文件夹下所有java文件的 空格行数、注释行数、和代码行数
- Linux下统计文件行数 语法:wc [选项] 文件… 说明:该命令统计给定文件中的字节数、字数、行数。如果没有给出文件名,则从标准输入读取。wc同时也给出所有 指定文件的总统计数。字是由空格字符
- Linux下使用Shell脚本删除一个目录下的所有子目录和文件
- 在linux中怎样用命令完全拷贝一个目录下的所有文件(包括隐藏文件以及文件夹)到另外一个目录下
- Linux下统计代码行数--wc命令
- 统计文件夹内指定类型文件的代码行数(二)
- 使用FindFirstFile和FindNextFile查找某个目录下的所有文件(包括子目录)
- [原创]Python小工具 —— 计算 文件 或 文件夹及其所有子文件夹中所有文件 的 代码行数
- 利用Foundation框架写的小程序统计文件(文件夹内文件)的所有行数(或统计字数)
- wc递归统计代码行数 -- Linux/Unix 哲学魅力
- 遍历目录及子目录列出所有文件和文件夹的代码
- 用java统计一个目录(含子目录)下所有java源文件中代码行数