14.D: Appending Files with << | 14: File Utilities | 14.B: The cat command |
The symbol < stands for redirect standard input. It allows you to take input from a file instead of the (default) keyboard. For example, you can use it to run a program with input from a file.
The related symbol > stands for redirect standard output. It allows you to direct output to a file instead of the (default) video screen. For example, you can use it to run a program with output to a file.
You can use output redirection with the cat command to create a file:
% cat > hello
Hello World!
I am here!
^d
Here the control-d (^d ) is used to end data entry. Whatever lines you enter, including carriage returns, will be placed in the file hello.
Another way to use cat and < to create a file, is to copy any number of files into the present one
> cat hello .forward > old.text
Be careful not to use the same name for input and output files. If you do, cat creates the file first and will therefore erase your input file before writing the output file.
Now use the cat command to view the new file. (Quiz)
In the next section we will use the append symbol to input from and output to the same file.
14.D: Append with << | 14: File Utilities | 14.B: The cat command |