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

Access a shell prompt and issue commands with correct syntax

While preparing for RHCE RHEL 6 (available upto March 31, 2016), I came across this website which does an easy to follow cheat sheet of sort for each topics under the RHCE/RHCSA Exam objectives. I was hugely impressed and wanted to do something similar. This is my attempt at creating a cheat sheet for RHCE/RHCSA RHEL 7.

Now to the topic. Anyone attempting RHCE should already know how to launch a terminal to access the shell and run commands. If you are really that fresh to Linux, among the many many resources available online I recommend Daniel Robin’s Linux Fundamental series and Introduction to Linux by the Linux Foundation at EdX.
Continue reading