wc – Counts the Number of Bytes, Words, and Lines of a File

The wc command is a Linux command that is used to count the number of bytes, words, and lines of a file. It is a simple yet powerful command that can be used to analyze text files and determine their size and content. The wc command is commonly used by Linux system administrators and developers to check the size of log files, code files, and other text-based files.


The basic syntax of the wc command is as follows:

wc [options] [file]

where options are the various flags that can be used with the command, and file is the name of the file that you want to analyze.

Example Usage

To count the number of lines, words, and bytes in a file named example.txt, you would use the following command:

wc example.txt

This would output something like the following:

 10  20 200 example.txt

where the first number represents the number of lines in the file, the second number represents the number of words in the file, and the third number represents the number of bytes in the file.

Specific Use Cases

  • Counting the number of lines in a log file to determine the amount of activity on a system.
  • Checking the size of a code file to ensure that it can be compiled and executed properly.
  • Analyzing the output of a script to determine how many lines of output it generates.


The wc command has several options that can be used to modify its behavior. The following table lists the available options and their descriptions:

Option Description
-c Displays the byte count of the file.
-w Displays the word count of the file.
-l Displays the line count of the file.
-m Displays the character count of the file.
-L Displays the length of the longest line in the file.

Troubleshooting Tips

  • If you receive an error message that says “No such file or directory”, make sure that you have entered the correct file name and that the file exists in the specified location.
  • If the output of the wc command does not match your expectations, double-check that you are using the correct options and that you have entered the command correctly.


  • The wc command can be used with multiple files at once. Simply list the file names as separate arguments after the wc command, like so: wc file1.txt file2.txt.
  • By default, the wc command counts bytes, words, and lines in a file. If you only want to count one of these metrics, use the appropriate option (i.e. -c for bytes, -w for words, or -l for lines).