Categories
Shell script

Redirection in Shell-Unix/linux

Redirection is a function common to most command-line interpreters, including various unix shells that can redirect standard streams to user specified locations.

UNIX STANDARD I/O Streams

0- stdin (Standard input)

1- stdout (Standard output)

2- stderr (standard error)

 

 

 

Redirecting standard input and standard output

simple redirection to a file:  $command  > file

redirection &  appending to a file:   $command >> file

Redirecting to and from the standard file handles

eg: $ command  2> file

executes the command & redirects standard error to file.

Merging of standard error into standard output can be obtained by

eg: $ find / -name .profile > results 2>&1

 

Redirect to multiple outputs

The standard command “tee” can be used to redirect output from a command to several destinations

eg: $  ls -lrt | tee xyz

this redirects the file list output to both “standard output” and “file xyz”.

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *