通过管道使用wc命令 - ○白子○ 的Blog

通过管道使用wc命令

[ 2004-05-13 02:22:07 | Author: seaboat ]
Font Size: Large | Medium | Small
wc命令可以用来计算单词,行或者字符的数量,比如:
$ wc file.txt
96 591 6629 file.txt
告诉你文件file.txt里面有96行,591个单词和6629个字符。用-l,-w或者-c参数分别只打印行,单词或者字符数,比如:
$ wc -l file.txt
96 file.txt

通过管道使用wc命令用来计算另一个命令所输出的。单词,行或者字符的数量。比如,ls命令列出所有当前目录底下的所有。文件和子目录。
$ ls
file1 file2 sdir1

要得到当前目录底下的文件和子目录数,用wc来计算ls命令输出的单词数量。
$ ls | wc -w
3

下面是更多的通过管道使用wc命令的例子。
$ sort addrbook | uniq | wc -l
计算文件addrbook里面的所有不重复的行数。

$ find ~ -name '*.Z' -print | wc -l
计算当前目录以及所有子目录底下的以.Z结尾的文件数。

$ grep 'urgent' TODO | wc -l
计算文件TODO里面的所有含有字符串“urgent”的行数。

$ ps aux | grep 'liz' | wc -l
计算当前进程中的所有属于用户liz的进程数。

$ who | wc -l
计算当前登录的用户数。
Comments Feed Comments Feed: http://www6.webng.com/seaboat/feed.asp?q=comment&id=2

There is no comment on this article.

Post Comment
Smilies
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
Enable UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Username:   Password: