In this article, we are going to give an idea about the I/O Redirection and piping in Linux.
Before start learning, you should know few things.
STDIN (<) – Standard Input – 0
STDOUT (> and >>) – Standard Output – 1
STDERR (2>) – Standard Error – 2
mail -s “Test” firstname.lastname@example.org < .
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.
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.
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.
By using piping, You can give the one command output to another command as a input.
ps aux | less
ls -ltr | more