write the standard output (stdout) of the command to the file:
$ команда > файл
add standard output (stdout) command to file contents:
$ команда >> файл
write both standard output (stdout) and error output (stderr) commands to a file:
$ команда &> файл
Add both standard output (stdout) and error output (stderr) commands to the contents of the file:
$ команда &>> файл
You can write to the file not only the output of the command, but in general everything that you enter, and see in the terminal. for this you can use the script program.
it launches a new instance of the shell, and everything that you enter, and everything you receive in response, saves it to the file specified by the parameter. if this file is not specified, the default will be the file named typescript in the current directory. the shell can be terminated (and, accordingly, the script program can be script ), as usual, with the exit (often the shells are configured to execute the same command when receiving the ctrl + d keyboard shortcut ).
example:
$ script logfile Script started, file is logfile $ какие-нибудь команды $ exit
Now everything that you saw when executing какие-нибудь команды can be viewed in the logfile file. for example, using the less program. in order for the special characters used for coloring to be correctly displayed, the less need to pass the -R option to the less program:
$ less -R logfile
.bash_history- Mike