Thursday, 30 November 2023   |

How to Use ‘tee’ Command in Linux


The `tee` command in Linux is used to read from standard input and write to standard output and files simultaneously. It allows you to redirect the output of a command to both the screen and one or more files. Here's how you can use the `tee` command:

1. Basic usage:
   ```
   command | tee file.txt
   ```

   This command takes the output of `command` and writes it to both the screen and the `file.txt`. You can replace `command` with any command or pipeline.

2. Appending to a file:
   ```
   command | tee -a file.txt
   ```

   The `-a` option is used to append the output to the specified file. Without the `-a` option, `tee` overwrites the file.

3. Multiple output files:
   ```
   command | tee file1.txt file2.txt
   ```

   You can specify multiple file names separated by spaces. The output will be written to all the specified files in addition to the screen.

4. Using tee with sudo:
   ```
   command | sudo tee file.txt
   ```

   If you need to write to a file that requires root permissions, you can use `sudo tee`. This allows you to write to the file as the superuser.

5. Ignoring standard output:
   ```
   command | tee > /dev/null
   ```

   If you want to discard the output displayed on the screen and only write it to a file, you can redirect the standard output to `/dev/null`.

These are some common examples of using the `tee` command in Linux. The `tee` command is a handy tool when you want to save the output of a command to a file while still viewing it on the screen.


Date: 20 June 2023    Comments: 0


Comments - 0

There are no comments yet

Leave A Comment