Redirecting

From MEPIS Documentation Wiki

Jump to: navigation, search

Redirect output of a command to files with ">" or ">>"
> = overwite file. For example,

  echo "hello world!" > helloworld.txt 

>> = append to end. For example,

  echo "hello world!" >> helloworld.txt

You can use the same technique to get rid of messages by redirecting them to /dev/null by entering

  "command >/dev/null"

There are two types of messages:

  1. Standard output (stdout) - the normal output of the execution of a program.
  2. Standard error (stderr) - the output when the program encounters errors.

You can redirect them together or separately:

  "command >/dev/null" will redirect stdout only.
  "command 2>/dev/null" will redirect stderr only.
  "command &>/dev/null" will redirect both stdout and stderr.

Redirecting input: stdin can be redirected using "<" sign. For example a program can get its input from a file:

  "command < filename"

Redirecting standard input from a "here string"

  command <<< "string to be read as standard input"
Personal tools