If you want to put a commands output to a file, all you have to do is redirecting it. The '>
' '<
' '>>
' characters can be used for redirection. Each character has a special meaning.
>
character is used to redirect the output of a command to a file. More formally, you are redirecting its standard output to a file. So when you give the command below, the result will not be displayed on the screen.
<mendelson:~>ls -l /tmp > ls.output_fileThe system puts the data coming from standard output line to a file. Note that the file is created if it does not exist. If it exists, you loose the old content of that file.
<
character is used to redirect the input of a command from a file. More formally, you are redirecting the standard input from a file. In the command below, the inputs are read from the file, and written to standard output (screen). <mendelson:~>cat < tmpNote that the command above is the same as "cat tmp" command. The command itself does not read the content of the "tmp" file, but the system reads them and sends them to the command from standard input.
>>
is used to redirect the output of a command to the end of a file. If the file does not exist, then it is created. If a file exists, then outputs are written to the end of the file. (you do not loose the old data in that file) <mendelson:~>ls -l /usr >> ls.output_fileAfter the command above, there should be first the listing of /tmp from the previous command, and after that, the listing of /usr.
<mendelson:~>cat < tmp > dnm1The contents of "tmp" file is fed to cat and outputs are written to "dnm1" file. If any errors occur, then the error messages would be written to standard error, so they will appear on the screen. Since cat writes the input to output line by line, after this command, "tmp" and "dnm1" files will have the same content. This is a way of copying files.