Learn how to save terminal output to file in Linux Ubuntu and how to save terminal commands in Linux. Users can also save terminal session to file in Linux.
Save Terminal Output To File Using Redirects
Ubuntu users can save the terminal output using the STDOUT redirection operator > for redirecting/saving the output to a file. These in-built operators of the UNIX shell are default functions in Linux that can redirect the text output of a program to a file.
There are three STDOUT operators that can be used:
- The > redirects the command output to a file replacing any existing content on the file. The > operator will either generate a new file or replace the contents of a file with the output of the program.
- The >> redirects adds the command output at the end of the existing content of the file (if any).
- The 2> operator is a special kind of operator that will print errors reported back. This is highly useful for debugging.
In the example above, the > redirect saves the output of ls -l command to a text file named output.txt.