Operating Systems & Administration

[Day 2] 7. Redirection

D
DITISS Admin
••3 min read

Console Standard Files

The console operates with three internal standard files:

  1. Standard Input File: Used to take input.
  2. Standard Output File: Used to display output.
  3. Standard Error File: Used to display error messages.

These files are collectively referred to as standard files.


There are two ways to give output of one command to another: Redirection and Pipes


Redirection

Redirection allows you to control the flow of input and output in the console. There are three main types of redirection:

  1. Input Redirection:

    • Instead of taking input from the standard input file, you can take input from another file.
    • Operator:
      <
    • Example:
      cat < test.txt
  2. Output Redirection:

    • Instead of writing output to the standard output file, you can write it to another file.
    • Operator:
      >
    • Example:
      ls > lsout.txt
  3. Error Redirection:

    • Instead of writing errors to the standard error file, you can write errors to another file.
    • Operator:
      2>
    • Example:
      command 2> error.txt
    • You can redirect both standard output and standard error to the same file using:
      command > output.txt 2>&1

Pipes

Pipes allow you to connect the output of one command to the input of another. There are two types of pipes:

  1. Named Pipe:

    • Created using the
      mkfifo()
      function.
    • Can be used for two logically unrelated processes.
  2. Unnamed Pipe:

    • Created using the
      pipe()
      function.
    • Can be used for two related processes.

Note: Both pipes function similarly, but they are used under different circumstances.

!7. Pipe.png


Additional Notes

  • The
    bc
    command can be used to perform mathematical operations, and input redirection can also be applied here.
  • You can combine input and output redirection together, but not all commands support this.

Read Next

8/26/2026

[Day 3] 1. Revision

### **Process Control Block (PCB) in Linux** - The `task_struct` is a structure used to create the Process Control Block (PCB). - The size of...

8/26/2026

[Day 3] 2. Redirection

### **Redirection in Linux** In Linux, the three standard streams—**stdin** (standard input), **stdout** (standard output), and **stderr** (stand...