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?✗ Incorrect
The
-w option counts words only.What does
wc -l file.txt show?✗ Incorrect
-l counts lines only.How do you count characters including spaces with
wc?✗ Incorrect
-m counts characters including spaces.What does
wc file.txt output by default?✗ Incorrect
Without options,
wc shows lines, words, and bytes.What is the output of
echo "Hi" | wc -w?✗ Incorrect
The echo outputs one word "Hi", so
wc -w counts 1.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.