Free Hosting Online for WorkStations

< Previous | Contents | Next >

wc – Print Line, Word, And Byte Counts

The wc (word count) command is used to display the number of lines, words, and bytes contained in files. For example:



[me@linuxbox ~]$ wc ls-output.txt

7902 64566 503634 ls-output.txt

[me@linuxbox ~]$ wc ls-output.txt

7902 64566 503634 ls-output.txt


In this case it prints out three numbers: lines, words, and bytes contained in ls-out- put.txt. Like our previous commands, if executed without command line arguments, wc accepts standard input. The “-l” option limits its output to only report lines. Adding it to a pipeline is a handy way to count things. To see the number of items we have in our sorted list, we can do this:



[me@linuxbox ~]$ ls /bin /usr/bin | sort | uniq | wc -l

2728

[me@linuxbox ~]$ ls /bin /usr/bin | sort | uniq | wc -l

2728


Top OS Cloud Computing at OnWorks: