Or copy link
Copy link
wc is a command-line utility in Linux that stands for word count. It allows us to count the number of characters, words, and lines in a specified file. By default, this command returns three columns: the number of lines, words, and characters. If we use this command with a file, the fourth column shows the file name.
By default, the wc command returns the output to the console; however, we can redirect it to a specific file as well, if needed. In this tutorial, we will explore the Linux wc command with practical examples.
The wc is a text processing command that counts lines, words, bytes, and characters. It returns the output in the following sequence: the number of lines, words, characters, bytes, and file name. Additionally, we can combine wc with the grep command in Linux, cat command, or ls command using pipes to handle more advanced tasks.
The basic usage of the wc command implies wc followed by option (if any) and then the target file:
wc [OPTION]... [FILE]...
Here, FILE represents a target file whose newlines, words, characters, etc., need to be counted. The OPTION can be one of the following optional flags that are supported by the wc command:
In this section, we will explore some basic to advanced use cases of the Linux wc command, along with practical examples.
Run the wc command without any argument to display the number of lines, words, and bytes from the file:
wc exampleFile.txt
In the output, 4 shows the number of lines, 18 represents the total words, 129 shows byte count, and exampleFile.txt is the file name:
exampleFile.txt
Read also Exploring the Linux tr Command
You can specify the multiple files with space-separated syntax to show the count information of multiple files:
wc exampleFile.txt employeeNames.txt
The output displays the number of lines, words, and bytes, along with the names of both files:
You can run the wc command with the “-l” option to count only the number of total lines of the specified file:
wc -l exampleFile.txt
In the output screenshot, 4 represents the total lines and file name:
Use the -m flag with the wc command to count only characters of the specified file:
wc -m exampleFile.txt
The output displays the total number of characters, followed by the file name:
Similarly, you can use the -c or -w option to count bytes or words in a file.
Discover wc Command with Ultahost Linux VPS!
Ultahost offers Linux hosting with NVMe SSD storage, making it easy to practice the wc command. Use our affordable Linux VPS to enhance your command-line skills efficiently.
The ls command returns all available files and folders within the current working directory. To count the total number of files and directories, including hidden ones, you can run the following command:
ls | wc -l
This command returns the total files and directories of the current working directory. To count the files and subdirectories in a specific directory, use the following command:
ls dirName | wc -l
Change dirName to the name of the directory you want to count to see the total number of files and folders in it.
The wc is a Linux command that lets us count lines, words, bytes, and characters in files. It supports various options to customize the output and can be used with other commands for more complex tasks. Users can effectively analyze text files and directory contents by understanding the syntax and practical applications of the wc command. In this article, we discussed Linux wc command usage through practical examples.
The wc command allows you to count lines, words, and bytes in files, making it a valuable tool for your tasks. To enhance your experience and boost performance, consider Ultahost’s fast VPS hosting. With a range of affordable VPS plans, you can easily find one that fits your needs while practicing the wc command efficiently.
The wc command in Linux counts the number of lines, words, characters, and bytes in a specified file.
y the lines in a file by using the -l option as follows: “wc -l filename”.
To use the wc command in bash or Linux, use the syntax wc [OPTION]… [FILE]…, where [FILE] is the target file to be counted.
You can count the total files and directories by running the ls | wc -l command.
Yes, you can specify multiple files by separating them with space, like this: wc file1.txt file2.txt …
You can use the command ls dirName | wc -l to count the total items within a specific directory.
The wc command supports several options including -c, -m, -l, -w, –max-line-length, –help, and –version. All these options serve a specific functionality.
Jira is a popular project management tool developed by ...
The pipe command, denoted by the bar "|", is a powerful...
File Transfer Protocol (FTP) is a network protocol used...
The apropos command in Linux is an essential tool for b...
Port forwarding is a crucial technique for network admi...
Among the complexity of Linux systems user accounts ser...
Save my name, email, and website in this browser for the next time I comment.
Δ