echo "First" > data.txt writes "First" to data.txt, replacing any content.
Step 2: Analyze second command
echo "Second" >> data.txt appends "Second" after "First".
Step 3: Analyze third command
echo "Third" > data.txt overwrites entire file with "Third" only.
Final Answer:
Third -> Option A
Quick Check:
Last > overwrites file content [OK]
Hint: Last > overwrites file, ignoring previous appends [OK]
Common Mistakes:
Thinking >> always appends without overwrite
Assuming all lines remain after last >
Confusing ">" and ">>" effects
4. You want to append the output of date command to a file named times.log. Which command has an error and why?
A) date >> times.log
B) date > times.log
C) date >>> times.log
D) date >> times.log
medium
A. Correctly appends date output to times.log
B. Overwrites times.log with date output
C. Syntax error due to invalid operator >>>
D. gol.semit ot tuptuo etad sdneppa yltcerroC
Solution
Step 1: Check each redirection operator
A uses >> (append), B uses > (overwrite), C uses >>> (invalid), D uses >> (valid).
Step 2: Identify invalid syntax
Operator >>> is not valid in Linux shell, causing syntax error.
Final Answer:
Syntax error due to invalid operator >>> -> Option C
Quick Check:
>> is invalid operator [OK]
Hint: Only > and >> are valid output redirections [OK]
Common Mistakes:
Using >>> instead of >>
Thinking no space after >> is error
Confusing > and >> effects
5. 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?
hard
A. echo "Error occurred" > error.log
B. echo "Error occurred" >> error.log
C. echo "Error occurred" >! error.log
D. echo "Error occurred" < error.log
Solution
Step 1: Understand logging requirement
We want to keep old logs and add new errors, so appending is needed.
Step 2: Choose correct redirection operator
> overwrites file, >> appends to file. So >> is correct to keep old content.
Final Answer:
echo "Error occurred" >> error.log -> Option B
Quick Check:
Use >> to append logs without deleting [OK]
Hint: 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
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.