Challenge - 5 Problems
Redirection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the content of the file after this command?
Assume
What will be the content of
file.txt initially contains:Hello
What will be the content of
file.txt after running:echo "World" > file.txt
Linux CLI
echo "World" > file.txtAttempts:
2 left
💡 Hint
The single > operator overwrites the file content.
✗ Incorrect
The > operator replaces the entire content of the file with the new output. So the file will only contain "World".
💻 Command Output
intermediate1:30remaining
What will be the content of the file after appending?
Assume
What will be the content of
file.txt initially contains:Line1
What will be the content of
file.txt after running:echo "Line2" >> file.txt
Linux CLI
echo "Line2" >> file.txtAttempts:
2 left
💡 Hint
The >> operator adds the output to the end of the file.
✗ Incorrect
The >> operator appends the output to the existing file content, so the file will have both lines.
💻 Command Output
advanced2:00remaining
What is the output of this command sequence?
Given an empty file
log.txt, what will be the content after running these commands?echo "Start" > log.txt echo "Middle" >> log.txt echo "End" > log.txt
Linux CLI
echo "Start" > log.txt echo "Middle" >> log.txt echo "End" > log.txt
Attempts:
2 left
💡 Hint
The last command overwrites the file again.
✗ Incorrect
The first command writes "Start", the second appends "Middle", but the last command overwrites the file with "End" only.
💻 Command Output
advanced1:30remaining
What error or output occurs here?
What happens if you run this command when
readonly.txt is a read-only file?echo "New content" > readonly.txt
Linux CLI
echo "New content" > readonly.txtAttempts:
2 left
💡 Hint
You need write permission to overwrite a file.
✗ Incorrect
If the file is read-only, the shell cannot overwrite it and will show a permission denied error.
🧠 Conceptual
expert2:30remaining
How many lines will the file contain after this script?
Consider this script run in an empty directory:
How many lines will
for i in 1 2 3; do echo "Line $i" >> file.txt echo "Overwrite $i" > file.txt done
How many lines will
file.txt have after the loop finishes?Linux CLI
for i in 1 2 3; do echo "Line $i" >> file.txt echo "Overwrite $i" > file.txt done
Attempts:
2 left
💡 Hint
Each loop overwrites the file after appending.
✗ Incorrect
Each loop first appends a line, then immediately overwrites the file with one line. After 3 loops, only the last overwrite remains, so the file has 1 line.