3 Ways To Save Terminal Output to Files in Linux

Conveniently and flexibly

Yang Zhou
TechToFreedom

--

Anime scenery
Photo by spraayer on Wallhaven

If you are a programmer, especially if you’re a backend developer. It’s inevitable that you need to do something on a Linux terminal instead of a GUI. One obvious problem is that the terminal is not visual-friendly, especially when you want to check some large-size standard output (stdout).

A good solution is saving the hard-to-read stdout into a separate file and checking that file.

Based on different use scenarios, there are 3 different requirements:

  1. Just saving the terminal output to a file
  2. Print the output and save it to a file
  3. Record all input and output of the terminal and save it to a file

This article will introduce 3 methods for the above 3 tasks.

1. Angle brackets: Save Standard Output (stdout) to a File

If we just need to save stdout in a file, the angle brackets can make our lives easier.

For example, to save the list of all the files or directories under the current path to test.txt, the command is the following:

ls > test.txt

--

--