Challenge - 5 Problems
File Append 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 appending?
You have a file named
What will be the content of
log.txt containing:Line1
What will be the content of
log.txt after running this command?echo "Line2" >> log.txt
Attempts:
2 left
💡 Hint
Appending adds new content after existing content without removing it.
✗ Incorrect
The >> operator adds the new line after the existing content. So the file will have the original 'Line1' and then 'Line2' on the next line.
💻 Command Output
intermediate1:30remaining
What happens when appending with a missing file?
If
notes.txt does not exist, what will be the content of notes.txt after running?echo "Start" >> notes.txt
Attempts:
2 left
💡 Hint
Appending creates the file if it does not exist.
✗ Incorrect
The >> operator creates the file if it does not exist and then writes the content.
📝 Syntax
advanced2:00remaining
Which command correctly appends multiple lines to a file?
You want to append these two lines to
Which command will do this correctly?
data.txt:First line
Second line
Which command will do this correctly?
Attempts:
2 left
💡 Hint
Appending multiple lines can be done by multiple echo commands with >>.
✗ Incorrect
Option A appends each line separately without overwriting. Option A overwrites the file first, so only second line remains. Option A does not interpret \n as newline. Option A depends on echo -e support which is not portable.
🔧 Debug
advanced2:00remaining
Why does this append command overwrite the file instead of appending?
A user runs:
What is the problem with this command?
echo "New entry" > file.txt >> file.txt
What is the problem with this command?
Attempts:
2 left
💡 Hint
Order of redirection operators matters in bash.
✗ Incorrect
In bash, > truncates the file immediately, then >> appends. Since > runs first, the file is overwritten before appending.
🚀 Application
expert2:30remaining
How to append output of a command to a file safely in a script?
You want to append the output of
date command to timestamps.log inside a bash script. Which line is the best to do this safely and avoid overwriting?Attempts:
2 left
💡 Hint
Appending means adding without removing existing content.
✗ Incorrect
Option A appends the output of date to the file. Option A overwrites. Option A overwrites. Option A appends then truncates, so file ends empty.