Linux and Shell Programming

0 of 30 lessons complete (0%)

Module 7 Redirection, Pipes and Tee Command

Redirection

Redirection in Unix allows you to control where the input and output of commands go. This is incredibly useful for managing input and output streams, allowing you to, for instance, save command output to a file, or use a file as input for a command.

Linux Redirection

1. Standard Input (stdin):

command < input.txt

2. Standard Output (stdout):

command > output.txt

or

command >> output.txt

3. Standard Error (stderr):

command 2> error.txt

4. Combining stdout and stderr:

command &> output_and_error.txt

or

command &>> output_and_error.txt

5. Piping:

command1 | command2

Redirection Operators:

  • <: Redirects standard input from a file.
  • >: Redirects standard output to a file (overwrites existing content).
  • >>: Redirects standard output to a file (appends to existing content).
  • 2>: Redirects standard error to a file.
  • 2>>: Redirects standard error to a file (appends to existing content).
  • &>: Redirects both standard output and standard error to a file.
  • &>>: Redirects both standard output and standard error to a file (appends to existing content).
  • |: Sends the output of one command as the input to another.