echo "Start" > log.txt creates or overwrites log.txt with "Start".
Step 2: Analyze the next two append commands
Both echo "Step 1" >> log.txt and echo "Step 2" >> log.txt add lines at the end without deleting existing content.
Final Answer:
Start
Step 1
Step 2 -> Option D
Quick Check:
First > overwrites, then >> appends [OK]
Hint: First > overwrites, then >> adds lines [OK]
Common Mistakes:
Thinking >> overwrites file
Ignoring newline added by echo
Assuming only last echo remains
4. You want to append the line "Backup complete" to backup.log, but your script uses echo "Backup complete" > backup.log. What is the problem?
medium
A. The command appends but adds extra blank lines.
B. The command overwrites the file instead of appending.
C. The file backup.log will not be created.
D. The command will cause a syntax error.
Solution
Step 1: Understand the operator used
The single > operator overwrites the file content, replacing it with new text.
Step 2: Identify correct operator for appending
To add text without deleting existing content, >> should be used instead.
Final Answer:
The command overwrites the file instead of appending. -> Option B
Quick Check:
Use >> to append, not > [OK]
Hint: Use >> to append, > overwrites [OK]
Common Mistakes:
Using > when >> is needed
Expecting append but file is replaced
Thinking > causes syntax error
5. You have a script that logs user actions to actions.log. You want to ensure the file is created if missing and new actions are added without deleting old logs. Which command correctly appends the text "User logged in" to the file?
hard
A. echo "User logged in" >> actions.log
B. echo "User logged in" > actions.log
C. cat "User logged in" >> actions.log
D. echo "User logged in" < actions.log
Solution
Step 1: Confirm file creation and appending
The >> operator appends text and creates the file if it does not exist.
Step 2: Validate command correctness
echo "User logged in" >> actions.log appends the message correctly without deleting old logs.
Final Answer:
echo "User logged in" >> actions.log -> Option A
Quick Check:
>> appends and creates file if missing [OK]
Hint: Use echo text >> file to append and create file if missing [OK]
Common Mistakes:
Using > which overwrites logs
Using < which is input redirection
Using cat incorrectly to append text
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.