Challenge - 5 Problems
Pipe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this piped command?
Consider the command:
What is the output?
echo -e "apple\nbanana\ncherry" | grep 'a' | wc -lWhat is the output?
Linux CLI
echo -e "apple\nbanana\ncherry" | grep 'a' | wc -l
Attempts:
2 left
💡 Hint
Think about which words contain the letter 'a' and how many lines that produces.
✗ Incorrect
The echo command outputs three lines: apple, banana, cherry. The grep 'a' filters lines containing 'a': apple and banana. So 2 lines remain. wc -l counts these lines, outputting 2.
🧠 Conceptual
intermediate1:30remaining
Why do pipes chain commands in Linux?
Why do pipes (|) chain commands into workflows in Linux?
Attempts:
2 left
💡 Hint
Think about how data flows between commands.
✗ Incorrect
Pipes connect the output of one command directly to the input of the next, allowing commands to work together in a sequence.
📝 Syntax
advanced2:00remaining
Which command correctly uses pipes to filter and count?
You want to count how many lines in a file contain the word 'error'. Which command is correct?
Attempts:
2 left
💡 Hint
Remember how to chain commands with pipes and which commands accept file arguments.
✗ Incorrect
Option A correctly uses grep with the file argument and pipes its output to wc -l to count lines. Option A works but is less efficient (useless use of cat). Options B and D have syntax errors.
🔧 Debug
advanced2:00remaining
Why does this piped command fail?
What error does this command produce and why?
cat file.txt | grep 'pattern' | sort | uniq -c | grepLinux CLI
cat file.txt | grep 'pattern' | sort | uniq -c | grepAttempts:
2 left
💡 Hint
Look at the last command in the pipe and its required arguments.
✗ Incorrect
The last grep command is missing a pattern argument, so it raises an error about missing pattern.
🚀 Application
expert2:30remaining
How many lines does this pipeline output?
Given a file with 10 lines, 4 contain 'foo', 3 contain 'bar', and 2 contain both 'foo' and 'bar'. What is the output line count of:
cat file.txt | grep 'foo' | grep -v 'bar' | wc -lLinux CLI
cat file.txt | grep 'foo' | grep -v 'bar' | wc -l
Attempts:
2 left
💡 Hint
First filter lines with 'foo', then exclude those with 'bar'.
✗ Incorrect
4 lines have 'foo'. Of these, 2 also have 'bar'. grep -v 'bar' removes those 2, leaving 2 lines. wc -l counts these 2 lines.