close
» » How to save to a file the output terminal

How to save to a file the output terminal

Other
How to save to a file the output terminalIn this article we will talk about how to redirect the output of any terminal command (or console) of Linux Mint to a text file.
CrossOver Linux
At times, the output of some terminal commands can be overwhelming. For example, a list of programs that can be updated:
apt list --upgradable
Sometimes, for various reasons, it is more convenient to redirect the output of this command into a text file and view it using a convenient text editor.
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:
How to save to a file the output 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:
How to save to a file the output terminalAs 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:
any_command > file_name.txt
that is, after the command is specified >, in the result, the command output is saved to a file "file_name.txt".
A real example command:
apt list --upgradable > output.txt
After you run this command in the directory where you are in the terminal (default is home directory) creates a file output of this command, which we will conveniently be able to view using any text editor:
How to save to a file the output terminalHow to save to a file the output terminal 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:
apt list --upgradable >> output.txt
We redirected standard output to a file, but the error we displayed in the terminal and in the file the error text will not be added.
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.
command > output.txt
2. Standard output will be redirected to a file (in the terminal will not be visible). New information will be written to the end of an existing file.
command >> output.txt
3. Standard error stream will be redirected to a file (in the terminal will not be visible). If the file exists, it is overwritten.
command 2> output.txt
4. Standard error stream will be redirected to a file (in the terminal will not be visible). New information will be written to the end of an existing file.
command 2>> output.txt
5. Standard output and standard error together will be redirected to a file (in the terminal will not be visible). If the file exists, it is overwritten.
command &> output.txt
6. Standard output and standard error together will be redirected to a file (in the terminal will not be visible). New information will be written to the end of an existing file.
command &>> output.txt
7. Standard output is copied to a file (in the terminal will still be visible). If the file exists, it is overwritten.
command | tee output.txt
8. Standard output is copied to a file (in the terminal will still be visible). New information will be written to the end of an existing file.
command | tee -a output.txt

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:
sudo lshw
How to save to a file the output terminalBut not very convenient to read this information in the terminal.
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:
sudo lshw -html > system_info.html
In the current directory will create a html file that you can open the file in any browser:
How to save to a file the output terminal 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,
Good Luck!!!
source​​​

Print version

Add comments

  • Local comments
  • Facebook comments
  • bowtiesmilelaughingblushsmileyrelaxedsmirk
    heart_eyeskissing_heartkissing_closed_eyesflushedrelievedsatisfiedgrin
    winkstuck_out_tongue_winking_eyestuck_out_tongue_closed_eyesgrinningkissingstuck_out_tonguesleeping
    worriedfrowninganguishedopen_mouthgrimacingconfusedhushed
    expressionlessunamusedsweat_smilesweatdisappointed_relievedwearypensive
    disappointedconfoundedfearfulcold_sweatperseverecrysob
    joyastonishedscreamtired_faceangryragetriumph
    sleepyyummasksunglassesdizzy_faceimpsmiling_imp
    neutral_faceno_mouthinnocent
Your favorite Linux distribution is Other polls