6个WC命令示例计算Linux中的行,字,字符数

在的Unix / Linux操作系统的 WC( 字数 )命令来查找 新行数字数字节和字符由file参数指定的文件,一个指望。 wc命令的语法如下图所示。
# wc [options] filenames
以下是命令提供的选项和用法。
wc -l : Prints the number of lines in a file.
wc -w : prints the number of words in a file.
wc -c : Displays the count of bytes in a file.
wc -m : prints the count of characters from a file.
wc -L : prints only the length of the longest line in a file.
那么,让我们看看我们如何能够在这篇文章中使用 'WC'命令与他们的一些可用参数和示例。 我们已经使用了 'youcl.txt'文件用于测试的命令。 让我们来看看该文件使用的输出 cat命令 ,如下图所示。
[root@youcl ~]# cat youcl.txt
Red Hat
CentOS
Fedora
Debian
Scientific Linux
OpenSuse
Ubuntu
Xubuntu
Linux Mint
Pearl Linux
Slackware
Mandriva

WC命令的基本示例

不传递任何参数的 'WC'命令将显示 “youcl.txt'文件的一个基本结果。 如下所示的三个数字是 12的文件 (行数 ),16( 字数 )和 112( 字节数 )。
[root@youcl ~]# wc youcl.txt
12  16 112 youcl.txt

2.计算行数

要在文件计数换行符号使用选项 “-L”,打印指定文件中的行数。说,以下命令将显示文件中换行符的计数。在输出中,作为计数和第二字段分配的第一字段是文件的名称。
[root@youcl ~]# wc -l youcl.txt
12 youcl.txt

3.显示字数

使用带有 'WC'命令打印一个文件中的单词数 “-w”的说法。键入以下命令以计算文件中的单词。
[root@youcl ~]# wc -w youcl.txt
16 youcl.txt

4.计数字节和字符数

当使用选择 '-c''-m'与' 厕所 '命令将分别在文件打印 字节字符 数目
[root@youcl ~]# wc -c youcl.txt
112 youcl.txt
[root@youcl ~]# wc -m youcl.txt
112 youcl.txt

5.显示最长行的长度

'WC'命令允许一个参数 “-L”,它可以用于打印出的最长( 字符数 )行中的文件的长度。 因此,我们在一个文件中的最长的字符行(' 科学的Linux')。
[root@youcl ~]# wc -L youcl.txt
16 youcl.txt

6.检查更多WC选项

有关 wc命令的详细信息和帮助,简单的运行的 “WC -help”或在命令行“ 人厕所 ”。
[root@youcl ~]# 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: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'wc invocation'
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏