Linux has a very powerful and efficient command-line interface (CLI), but while working with CLI sometimes the user may need to save the outputs of some commands for future reference or analysis. Linux provides powerful tools for saving the output of commands to files, making it easier to generate logs, store results for later analysis, or troubleshoot issues.
Table of Contents
- Method 1: Using Redirection Operator
- Using the
>
Operator (Overwrite Output) - Using the
>>
Operator (Append Output)
- Using the
- Method 2: Using the
tee
Command- Overwriting with
tee
- Appending with
tee
(-a
Option)
- Overwriting with
Method 1: Using Redirection Operator
Redirection operators (> and >>) are the most commonly used tools in Linux for saving command output to a file. They redirect the output of a command to a file instead of displaying it on the terminal.
Using ‘>’ Operator:
Redirects output to a file and overwrites any existing content.
$> command > output_file
We have created a file “File1.txt” with some text and we redirect the output of echo command into this file using “>” for demonstration.

Using ‘>>’ Operator:
Redirects output to a file and appends to the existing content.
$> command >> output_file
We have created a file “File1.txt” with some text and we append the output of echo command into this file using “>>” for demonstration.

Method 2: Using tee command
The tee command writes the output of a command to a file and displays it on the terminal simultaneously. This is especially useful when you want to see the command’s output while saving it to a file.
Overwriting with tee:
Syntax:
$> command | tee output-file
The command ’s output is piped (|) into the tee command. Thus, the tee command writes the output to output-file and displays it on the terminal.
We have created a file “File1.txt” with some text and we redirect the output of echo command into this file using tee command for demonstration.

Appending with tee:
To append the output of a command to a file without overwriting its contents, use the -a option with tee.
Syntax:
$> command | tee -a output-file
The -a flag appends the output of the command to output-file. Therefore, the existing content of output-file remains intact.
We have created a file “File1.txt” with some text and we append the output of echo command into this file using tee command for demonstration.

The ability to save command output to a file is a fundamental feature of Linux. Whether you’re troubleshooting, generating logs, or saving data for later use, these techniques help streamline your workflow.
Method | Use Case |
> | Overwrite a file with new command output. |
>> | Append output to a file without erasing data. |
tee | Save output to a file while displaying it. |
tee -a | Append output to a file and display it |