There are 3 types of file descriptors in unix. They are
  • stdin
  • stdout (1)
  • stderr (2)



You can do redirection in the following ways:
  • stdout to file
  • stderr to file
  • stdout to stderr
  • stderr to stdout
  • stderr and stdout to file


Examples:

1. Redirection from stdout to file

Code:
date > file.dat
2. Redirection from stderr to file

Code:
grep -z pattern filename 2 > error_log
3. Redirection from stdout to stderr

Code:
ls -l 1>&2
4. Redirection from stderr to stdout

Code:
grep pattern * 2>&1

5. Redirecting both stdout and stderr to a file

Code:
echo "unix" & > output.data