0
0
Linux CLIscripting~20 mins

wc (word, line, character count) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WC Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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.txt
Linux CLI
wc file1.txt file2.txt
A
 3 10 50 file1.txt
 2 5 20 file2.txt
 6 15 70 total
B
 3 10 50 file1.txt
 2 5 20 file2.txt
 5 15 70 total
C
 3 10 50 file1.txt
 2 5 20 file2.txt
 5 15 60 total
D
 3 10 50 file1.txt
 2 5 20 file2.txt
 5 15 70 file2.txt
Attempts:
2 left
💡 Hint
Remember that wc sums lines, words, and characters for the total line.
💻 Command Output
intermediate
1: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.txt
Linux CLI
wc -w input.txt
A4 input.txt
B6 input.txt
CError: file not found
D5 input.txt
Attempts:
2 left
💡 Hint
Count the words separated by spaces.
📝 Syntax
advanced
1:00remaining
Correct usage of wc to count lines
Which option correctly counts only the number of lines in file.txt?
Awc -l file.txt
Bwc -c file.txt
Cwc -w file.txt
Dwc --lines file.txt
Attempts:
2 left
💡 Hint
The option for lines is a single letter.
🔧 Debug
advanced
1:30remaining
Identify the error in wc command usage
What error will this command produce?

wc -x file.txt
Linux CLI
wc -x file.txt
A
wc: invalid option -- 'x'
Try 'wc --help' for more information.
B0 file.txt
CCounts lines, words, and bytes normally
Dwc: file.txt: No such file or directory
Attempts:
2 left
💡 Hint
Check if -x is a valid wc option.
🚀 Application
expert
2: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?
Awc -w a.txt b.txt c.txt | grep total | awk '{print $2}'
Bwc -w a.txt b.txt c.txt | head -1 | awk '{print $1}'
Cwc -w a.txt b.txt c.txt | tail -1 | awk '{print $1}'
Dwc -w a.txt b.txt c.txt | awk '{sum += $1} END {print sum}'
Attempts:
2 left
💡 Hint
The total line is the last line of wc output when multiple files are given.