Linux-Redirectors
-
>
(Output Redirection):- Redirects the standard output (stdout) of a command to a file. If the file exists, it is overwritten.
command > output.txt -
>>
(Append Output):- Appends the standard output of a command to a file. If the file doesn't exist, it is created.
command >> output.txt -
<
(Input Redirection):- Redirects the standard input (stdin) of a command from a file.
command < input.txt -
|
(Pipe):- Redirects the output of one command as the input to another command.
command1 | command2
ls | sort | tee sorted_file_list.tx -
2>
(Standard Error Redirection):- Redirects the standard error (stderr) of a command to a file.
command 2> error.txt -
2>>
(Append Standard Error):- Appends the standard error of a command to a file.
command 2>> error.txt -
&>
(Redirect Standard Output and Error):- Redirects both standard output and standard error to a file.
command &> output_and_error.txt -
2>&1
(Merge Standard Error with Standard Output):- Redirects standard error to the same location as standard output.
command 2>&1 -
/dev/null
(Null Device):- Discards data. Useful for suppressing output.
command > /dev/null
ls /fake/directory 2> /dev/null -
tee
(Split Output):- Reads from standard input and writes to standard output and files simultaneously.
command | tee output.txt
ls | tee peanuts.txt banan.txt