Redirections can be sometimes confusing to learn and utilize effectively. We will try to explain it in the simplest possible way that we think is effective. Please feel free to suggests a better approach to explaining it.
Firstly, the 3 basic redirections.
- < ; this less than symbol is to instruct the shell to read from a file instead of the standard input (stdin) which is generally the keyboard. As an example, assuming that you have a file 2compute and using the command bc (basic calculator), you can redirect the content of 2compute for bc.
# cat 2compute
1 + 1
2 / 2
# bc < 2compute
2
1
#
- > ; the greater than symbol is to redirect the standard out (stdout) to a file instead of the screen/monitor (depending on what stdout is defined as). As an example, the ls command which list the content of your directory will display it on your terminal. We can redirect the output into a file (we use mydirectory as an example)
# ls
bin Desktop Distribution Documents susetips
# ls > mydirectory
# cat mydirectory
bin
Desktop
Distribution
Documents
mydirectory
susetips
- >> ; similarly to the > symbol, using double greater than will append to the specified file as oppose to overwriting the file (if it exists). Following our previous example, if you use the single >, it will overwrite the old file. Using the double >, it will append to it.
# cat mydirectory
bin
Desktop
Distribution
Documents
mydirectory
susetips
# ls > mydirectory
# cat mydirectory
bin
Desktop
Distribution
Documents
mydirectory
susetips
#ls >> mydirectory
# cat mydirectory
bin
Desktop
Distribution
Documents
mydirectory
susetips
bin
Desktop
Distribution
Documents
mydirectory
susetips
#
Next, the puzzling 2>&1



No comments yet.