wc command with examples in Linux / Unix

wc command with examples in Linux / Unix

wc command is used to print number of lines, words and bytes in a file. The abbreviation of wc is word count. wc command is the most easy way to find number of lines in a file. Mostly every one use wc command to find number of lines in a file.

wc command with examples in Lnux / Unix
In the below example wc command prints the number of lines, words and character present in the /etc/passwd file.

#wc /etc/passwd
123  165 5261 /etc/passwd
|    |   |
|    |   |
|    |   |_____Their are total of 5261 character in /etc/passwd file.
|    |
|    |______Their are total of 165 words in /etc/passwd file.
|
|_______ Their are total of 123 lines in /etc/passwd file.

Options of wc command:

-c — Prints the byte counts

-l — Prints the line counts

-w — Prints the word counts

-L — Print the length of the longest line

How to find number of lines in a file

#wc -l /etc/passwd

How to find number of words in a file

#wc -l /etc/passwd

How to find number of character in a file

#wc -c /etc/passwd

How to find the length of the longest line

#wc -L /etc/passwd

wc command with examples in Lnux / Unix




Leave a Reply

Your email address will not be published. Required fields are marked *