In this article we will talk about how to redirect the output of any terminal command (or console) of Linux Mint to a text file.At times, the output of some terminal commands can be overwhelming. For example, a list of programs that can be updated:
And someone just wants to log the execution of any commands in the system or error log. In General, everyone will find use of this opportunity.
Before proceeding to the discussion save the output of terminal to a file, some theory on the standard output streams Linux.
If in fact, in Linux has 3 standard streams:
stdin – stream is number 0, the standard input stream.
stdout – the stream number 1, the standard output stream.
stderr – the stream 2, stderr, diagnostic and debug messages.
When we execute any command in the terminal:
The output of all executed commands in the screenshot above, this is stdout – the standard output stream.
And here is the output from standard error stream – stderr:
As you can see in the screenshot, the rows with errors begin with the letter E: (error), and can be a warning information W: (warning).
With the definitions, names, standard streams understood. Now you can move on to how to save the terminal output to a file.
The basic method of saving to a file the output terminal
Standard output is redirected using the “>” symbol, that is the easiest way to redirect the output terminal to the file will look like the following:
A real example command:
If you specify a single character “>“, the file will be permanently overwritten when you re-run the command.
New information was added to the end of the file, and not overwritten the whole file, you need to use the double symbol “>>“. The command will look like the following:
Now I have described the most common way to redirect the standard output stream stdout into a text file. Now let us examine other ways.
8 basic ways to save terminal output to a file.
1. Standard output will be redirected to a file (in the terminal will not be visible). If the file exists, it is overwritten.
How to display complete information about your computer and save this information to the html or pdf.
In Linux there is a command that displays all the information about the computer in terminal lshw (list hardware).
You have to run it as root with sudo:
This command has a parameter -html which allows you to display this information in html.
Now that we have learned to redirect the output of terminal to a file, let’s derive information about the system and the computer in easy to read html file:
And now, if we want to save in pdf all of this information, select print (CTRL-P), select pdf and click “Print”.
May the Force be with you,