Challenge - 5 Problems
WC Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of wc with multiple files
What is the output of the following command if file1.txt contains 3 lines, 10 words, and 50 characters, and file2.txt contains 2 lines, 5 words, and 20 characters?
wc file1.txt file2.txtLinux CLI
wc file1.txt file2.txt
Attempts:
2 left
💡 Hint
Remember that wc sums lines, words, and characters for the total line.
✗ Incorrect
The wc command outputs lines, words, and characters for each file, then sums them for the total line. Here, 3+2=5 lines, 10+5=15 words, 50+20=70 characters.
💻 Command Output
intermediate1:30remaining
Counting words only with wc
What is the output of this command if input.txt contains the text "Hello world from Linux CLI"?
wc -w input.txtLinux CLI
wc -w input.txtAttempts:
2 left
💡 Hint
Count the words separated by spaces.
✗ Incorrect
The text has 5 words: Hello, world, from, Linux, CLI. The -w option counts words only.
📝 Syntax
advanced1:00remaining
Correct usage of wc to count lines
Which option correctly counts only the number of lines in file.txt?
Attempts:
2 left
💡 Hint
The option for lines is a single letter.
✗ Incorrect
The -l option counts lines. -c counts bytes, -w counts words, and --lines is not a valid option.
🔧 Debug
advanced1:30remaining
Identify the error in wc command usage
What error will this command produce?
wc -x file.txtLinux CLI
wc -x file.txt
Attempts:
2 left
💡 Hint
Check if -x is a valid wc option.
✗ Incorrect
The -x option is not valid for wc, so it produces an invalid option error.
🚀 Application
expert2:30remaining
Using wc in a script to count total words in multiple files
You want to write a script that sums the total number of words across three files: a.txt, b.txt, and c.txt. Which command will correctly output only the total word count?
Attempts:
2 left
💡 Hint
The total line is the last line of wc output when multiple files are given.
✗ Incorrect
When wc -w is run on multiple files, the last line shows the total word count. tail -1 gets that line, and awk '{print $1}' extracts the count.