Basics
Input/Output Redirection
Three things to remember:
stdindevice is the keyboardstdoutdevice is the screenstderris reserved for error output
Output Redirection
$ ls -al > listing will store output of ls -al in a file called listing
>> performs the same function but appends data instead of rewriting a file
Input Redirection
$ sort < listing will push the listing file to the sort command
Pipes
Pipes take the output of one command and feed it into another. You can give any command scrolling output by piping it through less like $ ls -l | less
Error Redirection
When an application has an error, this goes to stderr which can be pushed to a file using 2> so if myscript.sh were to push an error, then $ myscript.sh 2> errors would push only the errors to a file called error. The 2 in the redirect specifies to redirect stderr, with normal output showing on the screen. You can write all output and errors to the same file using something like $ myscript.sh > allout.txt 2>&1
Last updated
Was this helpful?