0
0
Bash Scriptingscripting~5 mins

Appending to files (>>) in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the '>>' operator do in bash scripting?
The '>>' operator appends the output of a command to the end of a file without overwriting the existing content.
Click to reveal answer
beginner
How would you add the text 'Hello World' to the end of a file named 'greetings.txt'?
Use the command: echo "Hello World" >> greetings.txt. This adds the text to the file without deleting existing content.
Click to reveal answer
beginner
What happens if the file does not exist when you use '>>' to append?
If the file does not exist, bash creates a new file and then appends the output to it.
Click to reveal answer
beginner
Compare '>' and '>>' operators in bash.
'>' overwrites the file content with new output, while '>>' adds new output to the end of the file without removing existing content.
Click to reveal answer
beginner
Why is appending to files useful in scripting?
Appending lets you keep a log or add new data continuously without losing previous information, like saving multiple command outputs in one file.
Click to reveal answer
What does the command echo "Test" >> file.txt do if file.txt exists?
AAdds 'Test' to the end of file.txt
BDeletes file.txt and writes 'Test'
CShows an error
DReads file.txt content
If file.txt does not exist, what happens when you run echo "Hello" >> file.txt?
AAn error is shown
Bfile.txt is created and 'Hello' is added
CNothing happens
DThe command waits for input
Which operator overwrites the content of a file?
A>>
B|||
C&&
D>
Why might you prefer '>>' over '>' in a script that logs events?
ATo keep adding new logs without losing old ones
BTo erase old logs
CTo speed up the script
DTo delete the log file
What command appends the output of date to a file named log.txt?
Adate > log.txt
Bcat date >> log.txt
Cdate >> log.txt
Decho date >> log.txt
Explain how the '>>' operator works in bash scripting and give an example.
Think about adding text to a file without deleting what is already there.
You got /4 concepts.
    Describe the difference between '>' and '>>' operators and when you would use each.
    Consider what happens to the file content after running each operator.
    You got /4 concepts.