I/O Redirection and piping

 

In this article, we are going to give an idea about the I/O Redirection and piping in Linux.

I/O Redirection:

Before start learning, you should know few things.

STDIN (<) – Standard Input – 0

STDOUT (> and >>) – Standard Output – 1

STDERR (2>) – Standard Error – 2

Examples,

STDIN:

mail -s “Test” someone@xyz.com < .

If you run the above mail command normally, it will looks for the dot (.) to execute the command. Here we’re giving the dot (.) as a input for the mail command.

STDOUT:

ls -ltr > outputfile

Here the command ls -ltr will get executed and the output will be stored in a text file which is named as outputfile.

STDERR:

grep file * 2> /dev/null

Here the grep command will get executed and it’s show you lot of errors. So you can use 2> to redirect the errors to /dev/null.

Piping:

By using piping, You can give the one command output to another command as a input.

Example,

ps aux | less

ls -ltr | more

 

Related posts

Leave a Comment