wc command in Linux with Examples
wc command in Linux with Examples
wc command in Unix/Linux operating systems is used to find out number of line count, word count, byte and characters count in a files specified by the file arguments. This tutorial explains the wc command in detail.
Syntax
The syntax for wc command with its options are
wc [options] filenames
Usage of the commands
- wc -l : Prints the number of lines in a file.
- wc -w : prints the number of words in a file.
- wc -c : Displays the count of bytes in a file.
- wc -m : prints the count of characters from a file.
- wc -L : prints only the length of the longest line in a file.
Let us start with textfile.odt file you can use text files,pdf,..etc.
wc Command without any options
Run the following command to display the basic result of textfile.odt file.
[root@linuxhelp Desktop]# wc textfile.odt
48 270 12286 textfile.odt
In the output 48 is no of lines, 270 is no of words, 12286 is no of bytes.
Using wc command with &ndash l options
The below command is used to Count only Number of Lines in the file.
[root@linuxhelp Desktop]# wc -l textfile.odt
48 textfile.odt
Using wc command with &ndash w options
The below command helps to Count only Number of words in the file.
[root@linuxhelp Desktop]# wc -w textfile.odt
270 textfile.odt
To Count Number of Bytes and Characters
The below command is used to Count only Number of Bytes in the file.
[root@linuxhelp Desktop]# wc -c textfile.odt
12286 textfile.odt
The below command Count only Number of characters in the file.
[root@linuxhelp Desktop]# wc -m textfile.odt
8065 textfile.odt
Using wc command with &ndash L options
The below command is used to print out the length of longest line in a file.
[root@linuxhelp Desktop]# wc -L textfile.odt
999 textfile.odt
To Check the version wc command
Using the following command, you can check the version of wc command.
[root@linuxhelp Desktop]# wc --version
wc (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later < http://gnu.org/licenses/gpl.html> .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Paul Rubin and David MacKenzie.
Comments ( 0 )
No comments available