Absolute Control of Inputs and Outputs
The basic form of input is from your keyboard. They basic output is onto your monitor, in the terminal as text. These are referred to as Standard In and Out respectively. That is not always what you want. You may want to output of one command to go to a text file so you can compare that textfile with another to examine dissimilarities. The reasons are endless but luckily there is a simple symbol in the terminal to do this. It is a crude arrow in the form of > to direct output, and < for input.
Direct Output
An example has always been my favorite way of explaining something. Nothing is more concise and helpful to users. So my first example is performing a directory listing (using the ls command), but instead of reading the output, I will direct the output to a text file. I will open and read the text file to show you we did get the expected results. Here goes:
% ls > ls.txt
% cat ls.txt
examples
firstDir
helloWorld.txt
ls.txt
secondDir
It is important to point out that before issuing these commands, the ls.txt file did not exist, but if it did exist it would have been written over by our new command. When I wrote the first command, the terminal recognized that it needed to create the ls.txt file, then it executed the ls command and put the results into the ls.txt file. No output appeared in the terminal! As always, relative paths were used and the ls.txt file was created in the current directory, and therefore appears in the ls command! Pretty straight forward example but not necessarily useful.
One of the tips I have provided is a very useful hack exploiting this skill to create a simple text file. Check it out!
direct input »