0
0
Linux CLIscripting~10 mins

stdout redirection (>, >>) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - stdout redirection (>, >>)
Run command
Check redirection operator
Overwrite file
Write output
End
The shell runs a command, checks if output redirection is requested with > or >>, then either overwrites or appends the output to the file.
Execution Sample
Linux CLI
echo Hello > file.txt
cat file.txt

echo World >> file.txt
cat file.txt
This script writes 'Hello' to file.txt overwriting it, then appends 'World' to the same file, showing the file content after each step.
Execution Table
StepCommandActionFile Content AfterOutput to Screen
1echo Hello > file.txtOverwrite file.txt with 'Hello\n'Hello
2cat file.txtDisplay file.txt contentHelloHello
3echo World >> file.txtAppend 'World\n' to file.txtHello World
4cat file.txtDisplay file.txt contentHello WorldHello World
5EndNo more commandsHello World
💡 All commands executed; output redirected as specified; file.txt contains two lines.
Variable Tracker
VariableStartAfter Step 1After Step 3Final
file.txt content(empty)HelloHello WorldHello World
Key Moments - 3 Insights
Why does the first echo command overwrite the file instead of adding to it?
Because the > operator tells the shell to overwrite the file, as shown in execution_table step 1 where file.txt content changes from empty to 'Hello'.
Why does the second echo command add 'World' instead of replacing the content?
Because the >> operator appends output to the file, shown in execution_table step 3 where 'World' is added after 'Hello' without removing existing content.
Why is there no output to the screen when echo commands use > or >>?
Because output is redirected to the file, so nothing is printed on the screen during those steps, as seen in the 'Output to Screen' column for steps 1 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the content of file.txt after step 1?
A"Hello\nWorld"
B"World"
C"Hello"
D(empty)
💡 Hint
Check the 'File Content After' column for step 1 in the execution_table.
At which step does the file.txt content change from 'Hello' to 'Hello\nWorld'?
AStep 3
BStep 2
CStep 4
DStep 1
💡 Hint
Look at the 'File Content After' column and find when 'World' is appended.
If we replace >> with > in step 3, what would be the file content after step 3?
A"Hello\nWorld"
B"World"
C"Hello"
D(empty)
💡 Hint
Remember > overwrites the file, so the previous content is replaced.
Concept Snapshot
stdout redirection:
> overwrites file with command output
>> appends command output to file
Use > to start fresh file content
Use >> to add without deleting
No output shown on screen when redirected
Full Transcript
This lesson shows how stdout redirection works in Linux shell. When you run a command like 'echo Hello > file.txt', the > operator tells the shell to overwrite file.txt with the output 'Hello'. If you use 'echo World >> file.txt', the >> operator appends 'World' to the existing content. The execution table traces each command step by step, showing how the file content changes and what appears on the screen. Key points include understanding the difference between > and >> and why redirected output does not show on the terminal. This helps beginners see exactly how output redirection affects files and terminal display.