0
0
Linux CLIscripting~5 mins

stdout redirection (>, >>) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the > operator do in Linux command line?
The > operator redirects the standard output (stdout) of a command to a file, overwriting the file if it already exists.
Click to reveal answer
beginner
What is the difference between > and >> in Linux stdout redirection?
The > operator overwrites the file with new output, while >> appends the output to the end of the file without deleting existing content.
Click to reveal answer
beginner
How would you save the output of the command ls to a file named list.txt, replacing any existing content?
Use the command: ls > list.txt
Click to reveal answer
beginner
How do you add the output of the command date to the end of a file named log.txt without deleting existing content?
Use the command: date >> log.txt
Click to reveal answer
beginner
Why is stdout redirection useful in scripting and automation?
It allows saving command outputs to files for later use, logging, or processing, making scripts more powerful and organized.
Click to reveal answer
What happens when you run: echo "Hello" > greetings.txt?
ADeletes greetings.txt
BAppends Hello to greetings.txt
CPrints Hello on the screen
DCreates or overwrites greetings.txt with the text Hello
Which operator appends output to a file without deleting existing content?
A>
B>>
C<
D|
If you want to save the output of ls -l to a file and keep old data, which command is correct?
Als -l < file.txt
Bls -l > file.txt
Cls -l >> file.txt
Dls -l | file.txt
What does the command cat file.txt > output.txt do?
ACopies content of file.txt into output.txt, overwriting output.txt
BAppends content of file.txt to output.txt
CDisplays file.txt on screen
DDeletes output.txt
Why might you use stdout redirection in a script?
ATo save command output for later review
BTo delete files
CTo input data into commands
DTo change file permissions
Explain how > and >> differ when redirecting command output in Linux.
Think about what happens to existing file content.
You got /3 concepts.
    Describe a real-life situation where you would use stdout redirection in a script.
    Imagine you want to keep track of what a script does over time.
    You got /3 concepts.