April 22, 2017

Relevant Linux Features: Redirection

Relevant Linux Features: Redirection

Linux allows I/O to be redirected away from the default source or target.

The default source of STDIN is the keyboard, i.e. by default a command expects to get its input from the keyboard. To send input to a command, from a file, use the "<" redirection symbol.

The default target of STDOUT is the terminal or screen, i.e. by default a command expects to send its output to the screen. To redirect it elsewhere, use the ">" symbol:

Note: "command > file" sends the output to a file, "file". If "file" already exists, any existing content is overwritten. To instead append the output to the end of the file, use ">>" instead, i.e. "command >> file".

The default target of STDERR is the screen, i.e. by default a command expects to send its error output to the screen. To redirect it elsewhere, use the "2>" symbol:

Note: "command 2> file" send the output to a new file, "file". If "file" already exists, any existing content is overwritten. To instead append any new output to the end of the file, use "2>>" instead, i.e. "command 2>> file".

No comments:

Post a Comment