On Unix-like operating systems, the wc command counts the words, newlines, or bytes of each input file, and outputs the result.
This page covers the GNU/Linux version of wc.
Description
wc prints newline, word, and byte counts for each FILE, and a total if more than one FILE is specified. With no FILE, or when FILE is a dash ("-"), wc operates on standard input. (A word is a non-zero-length sequence of characters delimited by white space.)
- Description
- Syntax
- Examples
- Related commands
- Linux commands help
The options below can select which counts are printed. Counts are always in the following order: newline, word, character, byte, maximum line length.
Syntax
wc [OPTION]… [FILE]…
wc [OPTION]… –files0-from=F
Options
Examples
wc myfile.txt
Displays information about the file myfile.txt. Output resembles the following:
5 13 57 myfile.txt
Where 5 is the number of lines, 13 is the number of words, and 57 is the number of characters.
ls -1 | wc -l
This command returns the number of objects in the current directory. It uses the ls command to produce a single-column (-1) listing of the directory contents, which outputs one line per object; this output is piped to wc, which counts the lines (-l), and returns that number.
Related commands
cksum — Calculate and display a CRC for files.nl — Number the lines in a file.