Tuesday, March 16, 2004

The 'wc' command

No, the 'wc' command doesn't "flush" anything :-). Someone asked on the freebsd-questions list "How do I count the number of files beginning with 'db' in my current directory?". And the key command is 'wc'. It's a nice, simple little command
that does one thing and one thing well - it counts "words". If you don't
give it any flags, it tells you the number of lines, words, and bytes. Using
-l will count the number of lines. So you pipe the output of a command to
it and it will count stuff for you. Thus:




$ ls db* |wc -l


will give you a single number telling you the number of lines in its input;
in this case, the input is the output of 'ls db*', which is a simple listing
of all the files in the current directory beginning with 'db'. Thus, you
get a count of the number of files in the directory that begin with db.
A very typical Un*x way of doing things - string together building block
commands to get your output. Flexbile if arcane.



FreeBSD Hypertext Man Pages: wc



No comments:

Post a Comment