Bird
0
0

Which command should you use inside the script to save the error message "Error occurred" to the file without deleting old logs?

hard📝 Application Q15 of 15
Linux CLI - Pipes and Redirection
You have a script that logs errors to error.log. You want to keep all previous errors and add new ones each time the script runs. Which command should you use inside the script to save the error message "Error occurred" to the file without deleting old logs?
Aecho "Error occurred" > error.log
Becho "Error occurred" >> error.log
Cecho "Error occurred" >! error.log
Decho "Error occurred" < error.log
Step-by-Step Solution
Solution:
  1. Step 1: Understand logging requirement

    We want to keep old logs and add new errors, so appending is needed.
  2. Step 2: Choose correct redirection operator

    > overwrites file, >> appends to file. So >> is correct to keep old content.
  3. Final Answer:

    echo "Error occurred" >> error.log -> Option B
  4. Quick Check:

    Use >> to append logs without deleting [OK]
Quick Trick: Use >> to add logs, never > to avoid losing data [OK]
Common Mistakes:
  • Using > which erases old logs
  • Using < which is input redirection
  • Using invalid >! operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes