0
0
Linux CLIscripting~20 mins

stdout redirection (>, >>) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redirection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the content of the file after this command?
Assume file.txt initially contains:
Hello

What will be the content of file.txt after running:
echo "World" > file.txt
Linux CLI
echo "World" > file.txt
AHello
BHello\nWorld
CWorld
DWorld\nHello
Attempts:
2 left
💡 Hint
The single > operator overwrites the file content.
💻 Command Output
intermediate
1:30remaining
What will be the content of the file after appending?
Assume file.txt initially contains:
Line1

What will be the content of file.txt after running:
echo "Line2" >> file.txt
Linux CLI
echo "Line2" >> file.txt
ALine2
BLine1\nLine2
CLine1
DLine2\nLine1
Attempts:
2 left
💡 Hint
The >> operator adds the output to the end of the file.
💻 Command Output
advanced
2: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
AEnd
BStart\nMiddle
CStart\nMiddle\nEnd
DMiddle\nEnd
Attempts:
2 left
💡 Hint
The last command overwrites the file again.
💻 Command Output
advanced
1: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.txt
APermission denied error
BNew content is written to the file
CFile is created with new content
DNo output, command silently fails
Attempts:
2 left
💡 Hint
You need write permission to overwrite a file.
🧠 Conceptual
expert
2:30remaining
How many lines will the file contain after this script?
Consider this script run in an empty directory:
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
A0
B3
C6
D1
Attempts:
2 left
💡 Hint
Each loop overwrites the file after appending.