Linux and Unix wc command
Quick links
About wc
Syntax
Examples
Related commands
Linux and Unix main page
Short for word count, wc displays a count of lines, words, and characters in a file.
wc [-c | -m | -C ] [-l] [-w] [ file ... ]
| -c | Count bytes. |
| -m | Count characters. |
| -C | Same as -m. |
| -l | Count lines. |
| -w | Count words delimited by white space characters or new line characters. Delimiting characters are Extended Unix Code (EUC) characters from any code set defined by iswspace() |
| file | Name of file to word count. |
wc myfile.txt
Displays information about the file myfile.txt. Below is an example of the output.
5 13 57 myfile.txt
5 = Lines
13 = Words
57 = Characters
ls -1 | wc -l
Count how many files and directories are in the current directory. To prevent any confusion, the above command reads ls <dash><the #1> <pipe> ls <dash><the letter l>. This command uses the ls command to list files in a bare format and pipes the output into the wc command to count how many files are listed. When done properly, the terminal should return a single number indicating how many lines were counted and then return you to the prompt.
Keep in mind
that this is also counting the ./ and ../ directories.
