wc Command Overview
`wc` is one of the most fundamental text processing tools, providing various statistical information about files. Running `wc` without any options outputs the number of lines, words, and bytes. You can combine options to selectively output only the desired information.
Basic Output of wc
By default, `wc` outputs three columns. From left to right, they are 'line count', 'word count', and 'byte count', with the file name displayed at the end. If multiple files are specified, it shows statistics for each file along with a total sum.
Basic Output Example
wc data.txt
Outputs the number of lines, words, and bytes in the `data.txt` file.
Key Options
You can use various options of the `wc` command to selectively obtain only the necessary information.
1. Output Options
2. Other Options
Generated command:
Try combining the commands.
Description:
`wc` Executes the command.
Combine the above options to virtually execute commands with AI.
Common Use Cases
Learn how to obtain data statistics through various practical examples using `wc`.
Count Only Lines in a File
wc -l access.log
Checks the total number of lines in the log file `access.log` to determine how many connections there were today.
Count Specific Files Using Pipes
ls | grep '.txt' | wc -l
Counts the number of files with the '.txt' extension from the file list output by the `ls` command.
Count Words in Text
echo "Hello world, this is a test." | wc -w
Counts the number of words in a sentence entered directly into the terminal. Uses `echo` and pipes together.
Check Statistics for Multiple Files
wc file1.txt file2.txt
Outputs statistics for `file1.txt` and `file2.txt` separately, then shows the total sum at the end.
Output Only Bytes of a Specific File
wc -c report.pdf
Checks the size (in bytes) of the `report.pdf` file.