Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

bash
communitycreator
tee

What is tee command in bash?

Gutha Vamsi Krishna

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The tee command reads the standard input and simultaneously writes to a standard output, into the file(s).

Syntax

command | tee options filenames

Parameters

It takes the following parameters:

  • options:
    • -a: Appends to the file instead of overriding it.
    • --help: Displays the help message and exits.
    • --version: Displays the version and exits.
  • filename(s): Single or multiple file names separated by a space.

Let's take a look at an example.

Example

echo "List of files before executing the tee command"
#list files in present directory
ls
echo "Creating the how_to_ls text file with the tee command"
#create a text file with the tee command
man ls | tee how_to_ls.txt
echo "List of files after executing the tee command"
#list files in present directory
ls

Explanation

In the above code snippet:

  • Line 3: We print the list of files in the present directory before using the tee command with the ls command.
  • Line 7: We display the output of the command man ls and write it into a file how_to_ls.txt using the tee command.
  • Line 11: We print the list of files in the present directory after executing the tee command with the ls command. We can see in the output, how_to_ls.txt is created.

    RELATED TAGS

    bash
    communitycreator
    tee

    Grokking Modern System Design Interview for Engineers & Managers

    Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

    Keep Exploring