EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Linux WC

By Priya PedamkarPriya Pedamkar

Home » Software Development » Software Development Tutorials » Linux Tutorial » Linux WC

Linux WC

Definition of Linux WC

The Command WC (word count) in Linux OS allows to find out the word count, newline count, and the count of bytes or characters in a file that is mentioned by the file arguments. The output that is returned from word count command will give you the count of lines in a file or the number of words or character in a file.

Syntax:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The Syntax of WC Command is given as:

wc [options].. [file]..

Here options include:

  • wc -l: To print the number of lines in a file.
  • wc -c: To print the count of bytes in a file.
  • wc -w: To print the number of words in a file.
  • wc -m: To print the count of characters in a file.
  • wc -L: To print the length of the longest line in a file.

Advantages of Wc Command

WC Command in Linux helps to find out the below points:

  • Allows to find out the word count, newline count, and the count of bytes or characters in a file that is mentioned by the file arguments.
  • The output produced is the four-columnar by default.
  • The four columnar output arguments are: the first column gives the line that is in the file, the second column will give you the count of words in the file, the third column will give you the count of characters that is present in the file and the last column is the file name in the argument.

How does WC Command Work in Linux?

We can use –help command in Linux to find out the ways how WC Command works in Linux.

Syntax:

wc --help

Usage:

wc [OPTION]… [FILE]…
wc [OPTION]… –files0-from=F

We can print word, newline, and count the number of bytes for each FILE in the system, and also we can count the total number of lines if there are more than one FILE is mentioned in the arguments. A single word in the file is a non-zero-length of chars that might be delimited with white space. When there is no FILE, or if FILE is -, then we should be reading the standard input.

The options that are mentioned below might be used for selecting the counts that are printed and the ones that are always in the following order – newline, word, character, byte, the maximum length of the line.

Linux WC -1.1

Let us take an example file and perform wc command on it. Here we can list the data that is present in fruits.txt file by using cat command.

Popular Course in this category
Linux Training Program (16 Courses, 3+ Projects)16 Online Courses | 3 Hands-on Projects | 160+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (6,013 ratings)
Course Price

View Course

Related Courses
Kali Linux Training (3 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

cat fruits.txt
wc fruits.txt

Output:

Linux WC -1.2

When we perform the WC command on the above file, we can see that the output displayed is a four columnar manner. Here the first column gives the line that is in the file that is 5, the second column will give you the count of words in the file that is 5, the third column will give you the count of characters that is present in the file which is 38 and the last column is the file name in the argument that is fruits.txt.

Examples of WC Command in Linux

Below are the examples of options that can be used in WC command with their syntax and examples for better understanding.

1. Option -l

To print only the number of lines that are there in the file, we can use the option ‘l’. The output generated will be two columnar in which the first one is the count of a number of lines and second is the name of the file.

Syntax:

wc -l filename

Example:

wc -l fruits.txt

Output:

Linux WC -1.3

2. Option -w

To print only the number of words that are there in the file, we can use the option ‘w’. The output generated will be two columnar in which the first one is the count of a number of words and second is the name of the file.

Syntax:

wc -w filename

Example:

wc -w fruits.txt

Output:

Linux WC -1.4

3. Option -c

To print only the number of bytes present in the file, we can use the option ‘c’. The output generated will be two columnar in which first one is the count of number of bytes and second is the name of the file.

Syntax:

wc -c filename

Example:

wc -c fruits.txt

Output:

Output -1.5

4. Option -m

To print only the number of characters present in the file, we can use the option ‘m’. The output generated will be two columnar in which first one is the count of number of characters and second is the name of the file.

Syntax:

wc -c filename

Example:

wc -m fruits.txt

Output:

Output -1.6

5. Option -L

The option ‘L’ will help to find out the longest (in terms of long characters) line in the file. A character in the file will be considered that will include space, newline or tab.

Syntax:

wc -L filename

Example:

wc -L fruits.txt

Output:

Output -1.7

6. Option –version

The option of ‘version’ will help you to print the version of word count(wc) that is running on your system.

Syntax:

wc --version

Example:

wc --version

Output:

Output-1.8

Recommended Articles

This is a guide to Linux WC. Here we also discuss the definition and how does wc command work in linux? along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Linux Users
  2. Linux Mount Command
  3. Linux Shred
  4. Linux Inode

Linux Training Program (16 Courses, 3+ Projects)

16 Online Courses

3 Hands-on Projects

160+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Linux Training Program (16 Courses, 3+ Projects) Learn More