Vous êtes sur la page 1sur 2

RedHat RHCSA and RHCE Certi cation Exam Study Ebook ($35) Get This Book   

LINUX COMMANDS  18 I  TecMint :     


6 WC Command Examples to Count Number of Lines, Words, Start learning Linux in minutes 

Characters in Linux
 Vi/Vim Editor BEGINNER'S GUIDE 
by Ravi Saive | Published: February 25, 2013 | Last Updated: January 3, 2015
Learn vi/vim as a Full Text Editor 

 Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators | 4 Free Shell Scripting eBooks SHARE

The wc (word count) command in Unix/Linux operating systems is used to nd out number of newline count, +

word count, byte and characters count in a les speci ed by the le arguments. The syntax of wc command as
shown below.


# wc [options] filenames

The following are the options and usage provided by the command.
  Linux Foundation Certi cation 
wc -l : Prints the number of lines in a file. 2 Exam Study Guide to LFCS and LFCE
wc -w : prints the number of words in a file.
Displays the count of bytes in a file.
prints the count of characters from a file. 
wc -L : prints only the length of the longest line in a file.  

How to Add Linux Host to Nagios Monitoring

So, let’s see how we can use the ‘wc‘ command with their few available arguments and examples in this article.
Server Using NRPE Plugin
We have used the ‘tecmint.txt‘ le for testing the commands. Let’s nd out the output of the le using cat
command as shown below. How to Install Nagios 4.3.4 on RHEL, CentOS and

[root@tecmint ~]# cat tecmint.txt

Install Cacti (Network Monitoring) on
Red Hat
RHEL/CentOS 7.x/6.x/5.x and Fedora 24-12
Debian Google Chrome 63 Released – Install on
Scientific Linux RHEL/CentOS 7 and Fedora 26-20
How to Install Ubuntu 16.10/16.04 Alongside With
Windows 10 or 8 in Dual-Boot
Linux Mint
Pearl Linux
Slackware Tecmint’s Guide to Red Hat RHCSA / RHCE
Mandriva Certi cation Preparation Study Guide
4 Free Shell Scripting eBooks for Newbies and Administrators
1. A Basic Example of WC Command
The ‘wc‘ command without passing any parameter will display a basic result of ”tecmint.txt‘ le. The three
numbers shown below are 12 (number of lines), 16 (number of words) and 112 (number of bytes) of the le.

[root@tecmint ~]# wc tecmint.txt

12 16 112 tecmint.txt

2. Count Number of Lines

To count number of newlines in a le use the option ‘-l‘, which prints the number of lines from a given le. Say,
the following command will display the count of newlines in a le. In the output the rst led assigned as count
and second eld is the name of le.

[root@tecmint ~]# wc -l tecmint.txt

12 tecmint.txt
Linux System Administrator Bundle
with 7-Courses (96% off)

3. Display Number of Words

Add to Cart - $69
Using ‘-w‘ argument with ‘wc‘ command prints the number of words in a le. Type the following command to
 Ending In: 3 days
count the words in a le.
Computer Hacker Professional
[root@tecmint ~]# wc -w tecmint.txt Certi cation Course (96% Off)
16 tecmint.txt

Add to Cart - $59

4. Count Number of Bytes and Characters  Ending In: 4 days

When using options ‘-c‘ and ‘-m‘ with ‘wc‘ command will print the total number of bytes and characters
respectively in a le. LINUX EBOOKS

Introducing Learn Linux In One Week and Go

[root@tecmint ~]# wc -c tecmint.txt from Zero to Hero

112 tecmint.txt RedHat RHCE/RHCSA Certi cation Preparation
Linux Foundations LFCS/LFCE Certi cation
[root@tecmint ~]# wc -m tecmint.txt
112 tecmint.txt
Post x Mail Server Setup Guide for Linux
Ansible Setup Guide for Linux
5. Display Length of Longest Line Django Setup Guide for Linux
Awk Getting Started Guide for Beginners
The ‘wc‘ command allow an argument ‘-L‘, it can be used to print out the length of longest (number of
Citrix XenServer Setup Guide for Linux
characters) line in a le. So, we have the longest character line (‘Scienti c Linux‘) in a le.

[root@tecmint ~]# wc -L tecmint.txt     

16 tecmint.txt
Never Miss Any Linux Tutorials,
Guides, Tips and Free eBooks
6. Check More WC Options Join Our Community Of 150,000+ Linux Lovers
and get a weekly newsletter in your inbox
For more information and help on the wc command, simple run the ‘wc –help‘ or ‘man wc‘ from the command

[root@tecmint ~]# wc --help

Usage: wc [OPTION]... [FILE]...
or: wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. With no FILE, or when FILE is -,
read standard input.
-c, --bytes print the byte counts
-m, --chars print the character counts
-l, --lines print the newline counts
-L, --max-line-length print the length of the longest line
-w, --words print the word counts
--help display this help and exit
--version output version information and exit
Report wc bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'wc invocation'