0
0
Linux CLIscripting~5 mins

wc (word, line, character count) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the wc command do in Linux?
The wc command counts the number of lines, words, and bytes in a file or input.
Click to reveal answer
beginner
How do you use wc to count only the number of lines in a file named file.txt?
Use wc -l file.txt. The -l option tells wc to count lines only.
Click to reveal answer
beginner
What option do you use with wc to count only words?
Use the -w option. For example, wc -w file.txt counts words only.
Click to reveal answer
beginner
How can you count characters (including spaces) in a file using wc?
Use the -m option. For example, wc -m file.txt counts characters.
Click to reveal answer
beginner
What output do you get when you run echo "Hello world" | wc?
You get three numbers: lines, words, and bytes. For echo "Hello world", output is 1 2 12 meaning 1 line, 2 words, 12 bytes (including newline).
Click to reveal answer
Which wc option counts only words?
A-l
B-m
C-w
D-c
What does wc -l file.txt show?
ANumber of lines in file.txt
BNumber of words in file.txt
CNumber of characters in file.txt
DFile size in bytes
How do you count characters including spaces with wc?
A-l
B-w
C-s
D-m
What does wc file.txt output by default?
ALines, words, and bytes counts
BOnly lines count
COnly words count
DOnly characters count
What is the output of echo "Hi" | wc -w?
A2
B1
C3
D0
Explain how to use the wc command to count lines, words, and characters in a file.
Think about what each option counts and how to run wc on a file.
You got /3 concepts.
    Describe what output you get when running wc without any options on a text input.
    Remember the default order: lines, words, bytes.
    You got /5 concepts.