Input-output redirection in Linux

command file Sends output to file
command >> file Appends output to file
command 2> file Sends error to file
command 2>> file Sppends error to file
command > file 2>&1 Sends output and error to file
command >> file 2>>&1 Sppends output and error to file
command1 | command2 Output of command1 becomes the input of command2
command | tee file Sends output to both file and screen
0,1,and 2 are the file descriptor for stdin, stdout and stderr respectively

When you run a command, input is expected from the standard input which is the keyboard. The output and error messages go the standard output which is the screen. Input can come from a file or other command. This is called input redirection.

We can send the output to a file instead of the screen. This is called output redirection. We can do the same with error. We use piping to send the output of a command as input to another command.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s