{"id":23075,"date":"2023-10-31T07:30:50","date_gmt":"2023-10-31T07:30:50","guid":{"rendered":"https:\/\/linuxways.net\/?p=23075"},"modified":"2023-10-31T07:30:50","modified_gmt":"2023-10-31T07:30:50","slug":"how-to-save-terminal-output-to-a-file-in-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-save-terminal-output-to-a-file-in-ubuntu\/","title":{"rendered":"How to Save Terminal Output to a File in Ubuntu?"},"content":{"rendered":"<p>When working in the Ubuntu Operating System, the users mostly run several commands. Running or Executing Commands in a Terminal can be hard to track and once the Terminal is closed, all the history of the executed commands in the Terminal is wiped out of the System. Therefore, it is crucial sometimes for the users to keep track of the commands they execute. Ubuntu offers various commands that can be used in the Terminal to save the output in a Text File for later use.<\/p>\n<p>This article demonstrates every command that can be used to Save the Terminal Output to a File in Ubuntu.<\/p>\n<h2><strong>How to Save Terminal Output to a File in Ubuntu?<\/strong><\/h2>\n<p>The Terminal output can be redirected or saved to a Text File in Ubuntu through various methods. The output can then be used for later analysis or review, and also if you want to share the Terminal Output with any other user. The methods used to save the Terminal Output in a Text File are:<\/p>\n<ul>\n<li>Saving the Output through Redirect.<\/li>\n<li>Saving the Output using the \u201ctee\u201d Command.<\/li>\n<li>Saving the Output using the \u201cscript\u201d Command.<\/li>\n<\/ul>\n<p>Each method or approach is discussed below in detail.<\/p>\n<h2><strong>Method 1: Save the Terminal Output to a File through Output Redirection<\/strong><\/h2>\n<p>With the \u201credirect\u201d command, the output or an input of a file is used as an input for another file. In other words, you can save the Output generated by the Terminal in another text file. This output saved in another file can then be used as input for another file. The redirect command uses the Greater-than \u201c<strong>&gt;<\/strong>\u201d symbol. The basic syntax of the \u201credirect\u201d command in the Terminal is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">command<\/span> <span class=\"sy0\">&gt;<\/span> textFile.txt<br \/>\n<span class=\"kw3\">command<\/span> <span class=\"sy0\">&gt;&gt;<\/span> textFile.txt<\/div><\/div>\n<p>The \u201c<strong>&gt;<\/strong>\u201d and \u201c<strong>&gt;&gt;<\/strong>\u201d each have their own use, where the redirect \u201c&gt;\u201d saves the Output by Overwriting the Text File, and the redirect \u201c&gt;&gt;\u201d saves the Output by Appending the Output in the Text File. Additional Redirects used are the \u201c<strong>2&gt;<\/strong>\u201d, \u201c<strong>2&gt;&gt;<\/strong>\u201d, \u201c<strong>&amp;&gt;<\/strong>\u201d, and \u201c<strong>&amp;&gt;&gt;<\/strong>\u201d.<\/p>\n<h3><strong>Understanding the Redirects<\/strong><\/h3>\n<p>Before using the redirects, it is crucial to understand the use of each redirect and the options used with the redirects. The Detailed Explanation of each redirect is discussed below.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">command<\/span> <span class=\"sy0\">&gt;<\/span> textFile.txt<\/div><\/div>\n<p>The Output of the Command redirected or saved to the File can be seen in the File but it will not be displayed in the Terminal. The Error will be visible or displayed in the Terminal but it will not be saved in the File. The \u201c&gt;\u201d redirect Overwrites an Existing File, if any.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">command<\/span> <span class=\"sy0\">&gt;&gt;<\/span> textFile.txt<\/div><\/div>\n<p>The Output of the Command redirected or saved to the File can be seen in the File but it will not be displayed in the Terminal. The Error will be visible or displayed in the Terminal but it will not be saved in the File. The \u201c&gt;&gt;\u201d redirect Appends an Existing File, if any.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">command<\/span> <span class=\"nu0\">2<\/span><span class=\"sy0\">&gt;<\/span> textFile.txt<\/div><\/div>\n<p>The Output of the Command redirected to the File can be seen in the Terminal but it will not be saved in the File. The Error will only be visible in the File. The \u201c2&gt;\u201d redirect Overwrites an Existing File, if any.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">command<\/span> <span class=\"nu0\">2<\/span><span class=\"sy0\">&gt;&gt;<\/span> textFile.txt<\/div><\/div>\n<p>The Output of the Command redirected to the File can be seen in the Terminal but it will not be saved in the File. The Error will only be saved in the File. The \u201c2&gt;&gt;\u201d redirect Appends an Existing File, if any.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">command<\/span> <span class=\"sy0\">&amp;&gt;<\/span> textFile.txt<\/div><\/div>\n<p>The Output and the Error both won\u2019t be visible in the Terminal. The File will contain the Output as well as the Error. The \u201c&amp;&gt;\u201d redirect will Overwrite an Existing File, if any.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">command<\/span> <span class=\"sy0\">&amp;&gt;&gt;<\/span> textFile.txt<\/div><\/div>\n<p>The Output and the Error both won\u2019t be visible in the Terminal. The File will contain the Output as well as the Error. The \u201c&amp;&gt;\u201d redirect will Append an Existing File, if any.<\/p>\n<h3><strong>Concluding the Redirects<\/strong><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1712\" height=\"572\" class=\"wp-image-23076\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-1.png 1712w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-1-300x100.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-1-1024x342.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-1-768x257.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-1-1536x513.png 1536w\" sizes=\"auto, (max-width: 1712px) 100vw, 1712px\" \/><\/p>\n<p>Below, each Redirect is explained with examples for better understanding.<\/p>\n<h2><strong>Approach 1: Saving the Terminal Output to an Already Existing File by Overwriting the File<\/strong><\/h2>\n<p>The Redirect can be used to save the Terminal Output to a Text File by overwriting the existing text or content inside the Text File. In our case, we have the Text File \u201cabc.txt\u201d in our Home Directory: <img loading=\"lazy\" decoding=\"async\" width=\"1058\" height=\"280\" class=\"wp-image-23077\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-2.png 1058w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-2-300x79.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-2-1024x271.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-2-768x203.png 768w\" sizes=\"auto, (max-width: 1058px) 100vw, 1058px\" \/><\/p>\n<p>To view the content or text inside the file, use the \u201ccat\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> abc.txt<\/div><\/div>\n<p>The Text inside the \u201cabc.txt\u201d file will be displayed in the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"196\" class=\"wp-image-23078\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-3.png 786w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-3-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-3-768x192.png 768w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/p>\n<p>Now, to list the files in our current directory, and save the list in the file without displaying it in the terminal, the \u201c&gt;\u201d redirect will be used. This will overwrite the existing Text or content inside the \u201cabc.txt\u201d file and save the Output of the Terminal, in our case, the list of files and directories in the current path, to the Text file \u201cabc.txt\u201d:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span> <span class=\"sy0\">&gt;<\/span> abc.txt<\/div><\/div>\n<p>The command line moves to the next line without displaying the output in the Terminal indicating the output was saved in the \u201cabc.txt\u201d file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"778\" height=\"199\" class=\"wp-image-23079\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-4.png 778w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-4-300x77.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-4-768x196.png 768w\" sizes=\"auto, (max-width: 778px) 100vw, 778px\" \/><\/p>\n<p>To verify if the output of the Terminal was saved to the \u201cabc.txt\u201d file, use the \u201ccat\u201d command again:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> abc.txt<\/div><\/div>\n<p>As you can see, the previous text or content inside the file \u201cabc.txt\u201d is overwritten, and the output of the \u201cls -l\u201d command is saved in the Text File:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"821\" height=\"434\" class=\"wp-image-23080\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-5.png 821w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-5-300x159.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-5-768x406.png 768w\" sizes=\"auto, (max-width: 821px) 100vw, 821px\" \/><\/p>\n<h2><strong>Approach 2: Saving the Terminal Output to an Already Existing File by Appending the File<\/strong><\/h2>\n<p>The Redirect can also be used to save the Terminal Output to a Text File by Appending the Output to the existing text or content inside the Text File. We will use the \u201cabc.txt\u201d Text File again in our case. To view the Text inside the \u201cabc.txt\u201d Text File, we will use the \u201ccat\u201d command again:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> abc.txt<\/div><\/div>\n<p>The \u201cabc.txt\u201d Text File contains the Output of \u201cls -l\u201d currently:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"821\" height=\"410\" class=\"wp-image-23081\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-6.png 821w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-6-300x150.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-6-768x384.png 768w\" sizes=\"auto, (max-width: 821px) 100vw, 821px\" \/><\/p>\n<p>Now, to Append the text \u201cHello from Linux Ways\u201d, we can use the echo command along with the \u201c&gt;&gt;\u201d Redirect. The \u201c&gt;&gt;\u201d redirect will ensure to Append the \u201cecho\u201d Output to the Text File:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;Hello from Linux Ways&quot;<\/span> <span class=\"sy0\">&gt;&gt;<\/span> abc.txt<\/div><\/div>\n<p>The cursor moves to the next line ensuring the Output of the Terminal is saved in the file \u201cabc.txt\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"818\" height=\"111\" class=\"wp-image-23082\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-7.png 818w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-7-300x41.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-7-768x104.png 768w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/p>\n<p>To verify the Output saved in the Text File \u201cabc.txt\u201d, use the \u201ccat\u201d command again:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> abc.txt<\/div><\/div>\n<p>As you can see in the Terminal, the text is Appended in the file \u201cabc.txt\u201d without overwriting the previously added text:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"818\" height=\"385\" class=\"wp-image-23083\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-8.png 818w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-8-300x141.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-8-768x361.png 768w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/p>\n<h2><strong>Approach 3: Saving the Command Output Error to an Already Existing File by Overwriting the File<\/strong><\/h2>\n<p>The Redirect can also be used to save the Error of any command to a Text File by Overwriting the existing text or content inside the Text File. We will use the \u201cabc.txt\u201d Text File again in our case, and to view the Text inside the \u201cabc.txt\u201d Text File, we will use the \u201ccat\u201d command again:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> abc.txt<\/div><\/div>\n<p>The Text Inside the \u201cabc.txt\u201d command can be seen in the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"818\" height=\"351\" class=\"wp-image-23084\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-9.png 818w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-9-300x129.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-9-768x330.png 768w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/p>\n<p>Now, we will run the \u201cerrno\u201d command in the Terminal. The \u201cerrno\u201d command is not actually a command or the package is not installed in the Ubuntu System:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">errno<\/div><\/div>\n<p>As the errno is not a command, the Terminal is supposed to return an error saying the command is not found. Instead of displaying the Error in the Terminal, the \u201c2&gt;\u201d redirect will save the error in the file \u201cabc.txt\u201d by overwriting the file:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">errno <span class=\"nu0\">2<\/span><span class=\"sy0\">&gt;<\/span> abc.txt<\/div><\/div>\n<p>The cursor moves to the next line instead of displaying the output in the terminal. This means an error occurred and the error is saved in the text file \u201cabc.txt\u201d instead of showing in the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"822\" height=\"371\" class=\"wp-image-23085\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-10.png 822w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-10-300x135.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-10-768x347.png 768w\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" \/><\/p>\n<p>To verify if the error was saved in the Text File \u201cabc.txt\u201d, use the cat command again<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> abc.txt<\/div><\/div>\n<p>You can see the error is saved in the \u201cabc.txt\u201d file and the text inside the file was overwritten:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"818\" height=\"414\" class=\"wp-image-23086\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-11.png 818w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-11-300x152.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-11-768x389.png 768w\" sizes=\"auto, (max-width: 818px) 100vw, 818px\" \/><\/p>\n<h2><strong>Approach 4: Saving the Command Output Error to an Already Existing File by Appending the File<\/strong><\/h2>\n<p>The Redirect can also save the Error of any command by Appending the Error to the Text File. In our case, using the \u201cabc.txt\u201d Text File again, we can append the error of a command in it. To view the Text inside the \u201cabc.txt\u201d Text File, we used the \u201ccat\u201d command again and the Terminal displayed the Text inside the \u201cabc.txt\u201d File:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"821\" height=\"140\" class=\"wp-image-23087\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-12.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-12.png 821w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-12-300x51.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-12-768x131.png 768w\" sizes=\"auto, (max-width: 821px) 100vw, 821px\" \/><\/p>\n<p>Now, to append an error in the text file, in our case, we will run the \u201cpgadmin\u201d command. As pgadmin is not installed on our Ubuntu System, the Terminal will display an Error. To save by Appending the error in a text file without showing it on the Terminal, the \u201c2&gt;&gt;\u201d will be used:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">pgadmin <span class=\"nu0\">2<\/span><span class=\"sy0\">&gt;&gt;<\/span> abc.txt<\/div><\/div>\n<p>The Cursor will move to the next line without displaying an error on the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"821\" height=\"133\" class=\"wp-image-23088\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-13.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-13.png 821w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-13-300x49.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-13-768x124.png 768w\" sizes=\"auto, (max-width: 821px) 100vw, 821px\" \/><\/p>\n<p>The already added text will now contain the \u201cpgadmin\u201d error text as well. To display the text inside the file, we used the \u201ccat\u201d command again:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"819\" height=\"200\" class=\"wp-image-23089\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-14.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-14.png 819w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-14-300x73.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-14-768x188.png 768w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" \/><\/p>\n<h2><strong>Approach 5: Saving the Command Output Using the \u201c&amp;&gt;\u201d Command<\/strong><\/h2>\n<p>The \u201c&amp;&gt;\u201d Command can be used in two approaches where the Output of a Command can be saved as well as the Error of any Command.<\/p>\n<h3><strong>Saving the Error Output to a File using the \u201c&amp;&gt;\u201d Command<\/strong><\/h3>\n<p>The Redirect can also be used to save the Error of a command by Overwriting the Already Added Text in a Text File. In our case, using the \u201cabc.txt\u201d Text File again, we can overwrite the content or text inside the \u201cabc.txt\u201d file. To view the Text inside the \u201cabc.txt\u201d Text File, we used the \u201ccat\u201d command again and the Terminal displayed the Text inside the \u201cabc.txt\u201d File:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"824\" height=\"409\" class=\"wp-image-23090\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-15.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-15.png 824w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-15-300x149.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-15-768x381.png 768w\" sizes=\"auto, (max-width: 824px) 100vw, 824px\" \/><\/p>\n<p>Now, to Overwrite the existing file with the \u201c&amp;&gt;\u201d command, we will use the \u201cfirefox-dev\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">firefox-dev <span class=\"sy0\">&amp;&gt;<\/span> abc.txt<\/div><\/div>\n<p>As \u201cfirefox-dev\u201d is not installed on our Ubuntu System, the Terminal is supposed to display an error but as we are using the \u201c&amp;&gt;\u201d command, the error will be saved to the file abc.txt:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"822\" height=\"111\" class=\"wp-image-23091\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-16.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-16.png 822w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-16-300x41.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-16-768x104.png 768w\" sizes=\"auto, (max-width: 822px) 100vw, 822px\" \/><\/p>\n<p>Running the \u201ccat\u201d command again confirms that the saved Output from the Terminal has overwritten the File \u201cabc.txt\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"820\" height=\"127\" class=\"wp-image-23092\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-17.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-17.png 820w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-17-300x46.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-17-768x119.png 768w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><\/p>\n<h3><strong>Saving the Output to a File using the \u201c&amp;&gt;\u201d Command<\/strong><\/h3>\n<p>You can also use the \u201c&amp;&gt;\u201d redirect to save the Output of a Command that runs in the Terminal without displaying any error. The Redirect \u201c&amp;&gt;\u201d can also save the Output of an executed command by Overwriting the Already Added Text in a Text File. In our case, using the \u201cabc.txt\u201d Text File again, we can overwrite the content or text inside the \u201cabc.txt\u201d file. To view the Text inside the Text File, we used the \u201ccat\u201d command again and the Terminal displayed the Text inside the \u201cabc.txt\u201d File:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"817\" height=\"92\" class=\"wp-image-23093\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-18.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-18.png 817w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-18-300x34.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-18-768x86.png 768w\" sizes=\"auto, (max-width: 817px) 100vw, 817px\" \/><\/p>\n<p>Now, to overwrite the File \u201cabc.txt\u201d, the echo command is used and the output of the echo command will be saved to the \u201cabc.txt\u201d file using the \u201c&amp;&gt;\u201d redirect<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;LinuxWays is the Best&quot;<\/span> <span class=\"sy0\">&amp;&gt;<\/span> abc.txt<\/div><\/div>\n<p>The command will execute without any error, and the output will overwrite the \u201cabc.txt\u201d file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"819\" height=\"151\" class=\"wp-image-23094\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-19.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-19.png 819w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-19-300x55.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-19-768x142.png 768w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" \/><\/p>\n<p>To verify, we used the \u201ccat\u201d command again:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"821\" height=\"142\" class=\"wp-image-23095\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-20.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-20.png 821w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-20-300x52.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-20-768x133.png 768w\" sizes=\"auto, (max-width: 821px) 100vw, 821px\" \/><\/p>\n<h2><strong>Approach 6: Saving the Command Output Using the \u201c&amp;&gt;&gt;\u201d Command <\/strong><\/h2>\n<p>The \u201c&amp;&gt;&gt;\u201d Command can also be used in two approaches with one approach saving an executed output and the other approach saving the Error Output of a Command in a Text File.<\/p>\n<h3><strong>Saving the Error Output to a File using the \u201c&amp;&gt;&gt;\u201d Command<\/strong><\/h3>\n<p>The Redirect can also be used to save the Error of a command by Appending the output with the Already Added Text in a Text File. In our case, using the \u201cabc.txt\u201d Text File again, we can append the output with the already added content or text inside the \u201cabc.txt\u201d file. To view the Text inside the Text File, we used the \u201ccat\u201d command again and the Terminal displayed the Text inside the \u201cabc.txt\u201d File:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"106\" class=\"wp-image-23096\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-21.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-21.png 626w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-21-300x51.png 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/p>\n<p>Now, to append the Error output of the command, we used the \u201cfirefox-dev\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">firefox-dev <span class=\"sy0\">&amp;&gt;&gt;<\/span> abc.txt<\/div><\/div>\n<p>As the \u201cfirefox-dev\u201d package is not installed on our Ubuntu System, the command will display an error, and that error will be saved or appended in the \u201cabc.txt\u201d file instead of showing the error on the Terminal. The cursor moves to the next line without listing the error in the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"148\" class=\"wp-image-23097\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-22.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-22.png 626w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-22-300x71.png 300w\" sizes=\"auto, (max-width: 626px) 100vw, 626px\" \/><\/p>\n<p>The error is appended in the \u201cabc.txt\u201d file. To verify, the \u201ccat\u201d command is used again:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"170\" class=\"wp-image-23098\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-23.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-23.png 628w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-23-300x81.png 300w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><\/p>\n<h3><strong>Saving the Output to a File using the \u201c&amp;&gt;&gt;\u201d Command<\/strong><\/h3>\n<p>The \u201c&amp;&gt;&gt;\u201d redirect can also be used to save the Output of a Command that runs in the Terminal without displaying any error. The Redirect \u201c&amp;&gt;&gt;\u201d will save the Output of an executed command by Appending the output with the Already Added Text in a Text File. In our case, using the \u201cabc.txt\u201d Text File again, we can append the content or text inside the \u201cabc.txt\u201d file. To view the Text inside our previously used \u201cabc.txt\u201d Text File, we used the \u201ccat\u201d command again and the Terminal displayed the Text inside the \u201cabc.txt\u201d File:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"621\" height=\"116\" class=\"wp-image-23099\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-24.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-24.png 621w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-24-300x56.png 300w\" sizes=\"auto, (max-width: 621px) 100vw, 621px\" \/><\/p>\n<p>Now, to Append the Text inside the Text file, we used the \u201cecho\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;Learn more about Ubuntu on LinuxWays&quot;<\/span> <span class=\"sy0\">&amp;&gt;&gt;<\/span> abc.txt<\/div><\/div>\n<p>The output will not be displayed on the terminal rather it will append the output in the \u201cabc.txt\u201d file and the cursor will move to the next line:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"627\" height=\"158\" class=\"wp-image-23100\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-25.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-25.png 627w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-25-300x76.png 300w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/p>\n<p>To verify the Appended Text in the \u201cabc.txt\u201d file, we have used the \u201ccat\u201d command. You can see that the output is appended with the previously added text: <img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"190\" class=\"wp-image-23101\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-26.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-26.png 624w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-26-300x91.png 300w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/p>\n<h2><strong>Method 2: Save the Terminal Output to a File Using the \u201ctee\u201d Command<\/strong><\/h2>\n<p>The \u201ctee\u201d is another useful command for saving the Output of the Terminal in a File. Like the Redirect Method, the \u201ctee\u201d command can also be used in two approaches, where you can Overwrite an existing File in one approach, and in the other approach, you can Append the output to a Text File. Both approaches to saving the output to a text file are discussed below.<\/p>\n<h2><strong>Approach 1: Using \u201ctee\u201d Overwrite an Existing File by saving the Terminal Output in the File<\/strong><\/h2>\n<p>The \u201ctee\u201d command like the redirect can Overwrite an existing Text File by saving the output of the Terminal to that Text File. The basic syntax of the \u201ctee\u201d command in the Terminal is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"br0\">&#91;<\/span><span class=\"kw3\">command<\/span><span class=\"br0\">&#93;<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">tee<\/span> <span class=\"br0\">&#91;<\/span>fileName<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>In our case, to use the \u201ctee\u201d command, we will use the \u201cabc.txt\u201d file. To list the text inside our previously used \u201cabc.txt\u201d file, we used the \u201ccat\u201d command: <img loading=\"lazy\" decoding=\"async\" width=\"830\" height=\"453\" class=\"wp-image-23102\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-27.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-27.png 830w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-27-300x164.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-27-768x419.png 768w\" sizes=\"auto, (max-width: 830px) 100vw, 830px\" \/><\/p>\n<p>Now, to Overwrite the \u201cabc.txt\u201d file, we used the \u201cecho\u201d command along with the String:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;LinuxWays is the Best How-tos Website&quot;<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">tee<\/span> abc.txt<\/div><\/div>\n<p>This will display the output in the Terminal as well and Overwrite the file \u201cabc.txt\u201d with the output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"829\" height=\"483\" class=\"wp-image-23103\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-28.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-28.png 829w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-28-300x175.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-28-768x447.png 768w\" sizes=\"auto, (max-width: 829px) 100vw, 829px\" \/><\/p>\n<p>To verify, use the \u201ccat\u201d command again to list the text or content inside the abc.txt file. As you can see, the Text File \u201cabc.txt\u201d is overwritten with the new text:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"833\" height=\"515\" class=\"wp-image-23104\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-29.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-29.png 833w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-29-300x185.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-29-768x475.png 768w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/p>\n<p>You can also Overwrite the Existing Text File with the Terminal Error using the \u201ctee\u201d command. Note that with the \u201ctee\u201d command, if the Terminal responds with an error, the Error will only be displayed in the Terminal but it will not be saved in the Text File, although it will overwrite the Text File. The basic syntax to Overwrite the Existing File with the Output Error using the \u201ctee\u201d command is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"br0\">&#91;<\/span><span class=\"kw3\">command<\/span><span class=\"br0\">&#93;<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">tee<\/span> <span class=\"br0\">&#91;<\/span>fileName<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>In our case, we used the \u201cabc.txt\u201d file again and listed the text inside the text file using the \u201ccat\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> abc.txt<\/div><\/div>\n<p>The Already Added text inside the \u201cabc.txt\u201d file will be displayed in the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"833\" height=\"107\" class=\"wp-image-23106\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-30.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-30.png 833w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-30-300x39.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-30-768x99.png 768w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/p>\n<p>Now, to run a command that displays the Error, we used the \u201cfirefox-dev\u201d command as the \u201cfirefox-dev\u201d packages are not installed on our Ubuntu System:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">firefox-dev <span class=\"sy0\">|<\/span> <span class=\"kw2\">tee<\/span> abc.txt<\/div><\/div>\n<p>The Terminal will display an error as the \u201cfirefox-dev\u201d is not installed on our system and the error output will be displayed in the Terminal, but it will not be saved in the \u201cabc.txt\u201d file. Instead, the already written text in the abc.txt file will be removed. As you can see, the Terminal displays the Error:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"833\" height=\"163\" class=\"wp-image-23107\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-31.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-31.png 833w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-31-300x59.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-31-768x150.png 768w\" sizes=\"auto, (max-width: 833px) 100vw, 833px\" \/><\/p>\n<p>Now to verify the \u201cabc.txt\u201d file, we used the \u201ccat\u201d command again and you can see that the Output is not written in the Text File, rather it overwrites the whole \u201cabc.txt\u201d file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"832\" height=\"152\" class=\"wp-image-23108\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-32.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-32.png 832w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-32-300x55.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-32-768x140.png 768w\" sizes=\"auto, (max-width: 832px) 100vw, 832px\" \/><\/p>\n<h2><strong>Approach 2: Using \u201ctee -a\u201d Append an Existing File by saving the Terminal Output in the File<\/strong><\/h2>\n<p>The \u201ctee\u201d command can also Append the Output to an existing Text File by saving the output of the Terminal to that Text File. The basic syntax of the \u201ctee\u201d command to Append the Output in the Terminal is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"br0\">&#91;<\/span><span class=\"kw3\">command<\/span><span class=\"br0\">&#93;<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">tee<\/span> <span class=\"re5\">-a<\/span> <span class=\"br0\">&#91;<\/span>fileName<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>In our case, we will be using the \u201cabc.txt\u201d file again:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"826\" height=\"447\" class=\"wp-image-23109\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-33.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-33.png 826w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-33-300x162.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-33-768x416.png 768w\" sizes=\"auto, (max-width: 826px) 100vw, 826px\" \/><\/p>\n<p>Now, to Append the Output of the Terminal in our \u201cabc.txt\u201d file using the \u201ctee\u201d command, we will use the \u201cecho\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;The LinuxWays Guides provide you quality content with various to-dos&quot;<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">tee<\/span> <span class=\"re5\">-a<\/span> abc.txt<\/div><\/div>\n<p>This will Append the text to the \u201cabc.txt\u201d file and will display the Appended text in the Terminal as well:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"477\" class=\"wp-image-23110\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-34.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-34.png 907w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-34-300x158.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-34-768x404.png 768w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/p>\n<p>To verify the \u201cabc.txt\u201d command, we have used the \u201ccat\u201d command. As you can see, the Text Appends to the already added Text:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"908\" height=\"510\" class=\"wp-image-23111\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-35.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-35.png 908w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-35-300x169.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-35-768x431.png 768w\" sizes=\"auto, (max-width: 908px) 100vw, 908px\" \/><\/p>\n<p>If you want to Append the Existing Text File with the Terminal Error using the \u201ctee\u201d command, note that with the \u201ctee -a\u201d command, if the Terminal responds with an error, the Error will only be displayed in the Terminal but it will not be saved in the Text File. The basic syntax to Append the Existing File with the Output Error using the \u201ctee\u201d command is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"br0\">&#91;<\/span><span class=\"kw3\">command<\/span><span class=\"br0\">&#93;<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">tee<\/span> <span class=\"re5\">-a<\/span> <span class=\"br0\">&#91;<\/span>fileName<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>In our case, we will be using the \u201cabc.txt\u201d file again. To list the content inside the \u201cabc.txt\u201d file, we used the \u201ccat\u201d command again:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"899\" height=\"466\" class=\"wp-image-23112\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-36.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-36.png 899w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-36-300x156.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-36-768x398.png 768w\" sizes=\"auto, (max-width: 899px) 100vw, 899px\" \/><\/p>\n<p>Now, to run a command in our Terminal that displays an error, we used the \u201cfirefox-dev\u201d command in our case as it is not installed on our Ubuntu System:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">firefox-dev <span class=\"sy0\">|<\/span> <span class=\"kw2\">tee<\/span> <span class=\"re5\">-a<\/span> abc.txt<\/div><\/div>\n<p>The error output will be displayed in the Terminal and will append the \u201cabc.txt\u201d file, but it will not be saved in the \u201cabc.txt\u201d file. Only the already written text in the \u201cabc.txt\u201d file will be available:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"905\" height=\"484\" class=\"wp-image-23113\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-37.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-37.png 905w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-37-300x160.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-37-768x411.png 768w\" sizes=\"auto, (max-width: 905px) 100vw, 905px\" \/><\/p>\n<p>We will use the \u201ccat\u201d again command to verify the changes in our \u201cabc.txt\u201d file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"515\" class=\"wp-image-23114\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-38.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-38.png 907w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-38-300x170.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-38-768x436.png 768w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/p>\n<h2><strong>Method 3: Save the Terminal Output to a File Using the \u201cscript\u201d Command<\/strong><\/h2>\n<p>The \u201cscript\u201d is another useful command that saves the Output of the Terminal in a Text File. The script command starts recording the changes made in the Terminal and once the recording of the script is stopped, the changes made in the Terminal are saved in the Text File. The basic syntax to use the \u201cscript\u201d command is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">script <span class=\"br0\">&#91;<\/span>fileName<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>In our case, using the \u201cabc.txt\u201d file again, we will list the Text inside the \u201cabc.txt\u201d file using the \u201ccat\u201d command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"909\" height=\"517\" class=\"wp-image-23115\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-39.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-39.png 909w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-39-300x171.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-39-768x437.png 768w\" sizes=\"auto, (max-width: 909px) 100vw, 909px\" \/><\/p>\n<p>Now, to start the script, we will use the script command along with the file name \u201cabc.txt\u201d:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">script abc.txt<\/div><\/div>\n<p>This will start recording the script in the Terminal and will Overwrite the \u201cabc.txt\u201d Text File with all the commands that are executed after the script is started:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"127\" class=\"wp-image-23116\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-40.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-40.png 906w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-40-300x42.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-40-768x108.png 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/p>\n<p>Now, we will run the commands below one by one in the Terminal:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;hello from Linux ways&quot;<\/span><br \/>\nfirefox-dev<br \/>\n<span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;bye&quot;<\/span><\/div><\/div>\n<p>As you will run the commands, the output of these commands will also be displayed in the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"909\" height=\"205\" class=\"wp-image-23117\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-41.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-41.png 909w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-41-300x68.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-41-768x173.png 768w\" sizes=\"auto, (max-width: 909px) 100vw, 909px\" \/><\/p>\n<p>To stop the script, we will simply use the \u201cexit\u201d command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw3\">exit<\/span><\/div><\/div>\n<p>This will stop the script right away and will show the \u201cScript done\u201d message inside the Terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"901\" height=\"236\" class=\"wp-image-23118\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-42.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-42.png 901w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-42-300x79.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-42-768x201.png 768w\" sizes=\"auto, (max-width: 901px) 100vw, 901px\" \/><\/p>\n<p>To verify the \u201cabc.txt\u201d command, the \u201ccat\u201d command will be used again:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">cat<\/span> abc.txt<\/div><\/div>\n<p>As you can see, the changes made during the script are all listed or added in the \u201cabc.txt\u201d file:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"454\" class=\"wp-image-23119\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-43.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-43.png 906w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-43-300x150.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-23075-43-768x385.png 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>It is crucial sometimes to keep track of the commands you execute in the Terminal that can be used for later use, analysis, or even review. With the \u201credirect\u201d command, the \u201ctee\u201d command, and the \u201cscript\u201d command, you can save the output of the Terminal in a Text File. All these commands with various use cases are discussed in this article.<\/p>","protected":false},"excerpt":{"rendered":"<p>With the \u201credirect\u201d command, the \u201ctee\u201d command, and the \u201cscript\u201d command, you can save the output of the Terminal in a Text File. <\/p>","protected":false},"author":110,"featured_media":23105,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-23075","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/23075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=23075"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/23075\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/23105"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=23075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=23075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=23075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}