linux中计算行数,字数,字符数的10个wc命令示例 |
您所在的位置:网站首页 › 字节怎么算字数 › linux中计算行数,字数,字符数的10个wc命令示例 |
wc命令的功能为统计指定文件中的字节数、字数、行数, 并将统计结果显示输出。 代码语言:javascript复制# wc [options] filenames以下是该命令提供的选项和用法。 代码语言:javascript复制-c, --bytes 输出目标文件中字节的计数结果 -m, --chars 输出目标文件的中字符的计数结果 -l, --lines 输出目标文件中 行 的计数结果 --files0-from=F 从NUL-terminated指明的名字在文件F中的文件中读取,如果F是 - 则从标准输入读取 -L, --max-line-length 输出目标文件中最大行的长度 -w, --words 输出目标文件中单词的计数结果测试文件 代码语言:javascript复制[root@rumenz ~]# cat rumenz.txt Red Hat CentOS Fedora Debian Scientific Linux OpenSuse Ubuntu Xubuntu Linux Mint Pearl Linux Slackware Mandriva 1. wc 命令的基本示例这 wc 不传递任何参数的命令将显示 “的基本结果”rumenz.txt 文件。下面显示的三个数字是12(number of lines),16(number of words) 和112(number of bytes) 的文件。 代码语言:javascript复制[root@rumenz ~]# wc rumenz.txt 12 16 112 rumenz.txt 2. 计算行数要计算文件中的换行数,请使用选项 -l,它打印给定文件中的行数。假设,以下命令将显示文件中的换行数。在输出中,第一个字段指定为计数,第二个字段是文件名。 代码语言:javascript复制[root@rumenz ~]# wc -l rumenz.txt 12 rumenz.txt 3. 显示字数使用 -w与wc 命令打印文件中的单词数。键入以下命令以计算文件中的字数。 代码语言:javascript复制[root@rumenz ~]# wc -w rumenz.txt 16 rumenz.txt 4. 计算字节数和字符数使用选项时-c和-m和wc 命令将打印总数number of bytes和characters分别在一个文件中。 代码语言:javascript复制[root@rumenz ~]# wc -c rumenz.txt 112 rumenz.txt 代码语言:javascript复制[root@rumenz ~]# wc -m rumenz.txt 112 rumenz.txt 5. 统计最长行的长度这 wc命令允许一个参数-L,可以用来打印最长行(number of characters) 的长度。所以,我们有最长的字符行(Scientific Linux) 在一个文件中。 代码语言:javascript复制[root@rumenz ~]# wc -L rumenz.txt 16 rumenz.txt 6. 检查更多 WC 选项有关更多信息和帮助wc命令,简单地运行wc –help要么man wc 从命令行。 代码语言:javascript复制[root@rumenz ~]# wc --help Usage: wc [OPTION]... [FILE]... or: wc [OPTION]... --files0-from=F 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. -c, --bytes print the byte counts -m, --chars print the character counts -l, --lines print the newline counts -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 Report wc bugs to [email protected] GNU coreutils home page: General help using GNU software: For complete documentation, run: info coreutils 'wc invocation' 7.统计文件夹中文件个数代码语言:javascript复制> ls -l | grep "^-" |wc -l 23 8.统计文件夹中目录个数代码语言:javascript复制> ls -l | grep "^d" | wc -l 6 9.统计文件夹下文件个数,包括子文件代码语言:javascript复制> ls -lR | grep "^-" |wc -l 13089 10.统计文件夹下目录个数,包括子目录代码语言:javascript复制> ls -lR | grep "^d" | wc -l 1323相关文章 Linux之ls命令 linux中7个有趣的ls命令技巧 Linux之cat命令 Linux之wc命令 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |