Linux wc command
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.)
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
-c, --bytes | Print the byte counts. |
-m, --chars | Print the character counts. |
-l, --lines | Print the newline counts. |
--files0-from=F | Read input from the files specified by null-terminated names in file F; if F is "-" then read names from standard input. |
-L, --max-line-length | Print the length of the longest line. |
-w, --words | Print the word counts. |
--help | Display a help message, and exit. |
--version | Output version information, and exit. |
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 (Cyclic Redundancy Check) for files.
nl — Number the lines in a file.