Skip to content

Latest commit

 

History

History
42 lines (27 loc) · 1.16 KB

118-the-wc-command.md

File metadata and controls

42 lines (27 loc) · 1.16 KB

The wc command

the wc command stands for word count. It's used to count the number of lines, words, and bytes (characters) in a file or standard input then prints the result to the standard output.

Examples:

  1. To count the number of lines, words and characters in a file in order:
wc file.txt
  1. To count the number of directories in a directory:
ls -F | grep / | wc -l

Syntax:

wc [OPTION]... [FILE]...

Additional Flags and their Functionalities:

Short Flag Long Flag Description
-c --bytes print the byte counts
-m --chars print the character counts
-l --lines print the newline counts
- --files0-from=F read input from the files specified by NUL-terminated names in file F. If F is - then read names from standard input
-L --max-line-length print the maximum display width
-w --words print the word counts

Additional Notes:

  • Passing more than one file to wc command prints the counts for each file and the total conuts of them.
  • you can combine more whan one flag to print the result as you want.