Casbay Knowledge Base

Search our articles or browse by category below

Improve Linux VPS Server Management By Learning Basic Tee Commands

Last modified: October 1, 2022
You are here:
Estimated reading time: 1 min

Tee command is a Linux command commonly used in shell scripts. You may improve your Linux VPS server management skills by learning this command. This Linux command is used for reading standard input and writing them to both standard output and one or more files. To start learning the tee command, you will first have to access your VPS with SSH.

Tee Command Syntax

Here is a basic syntax to show the uses of the tee command.

wc -l file1.txt | tee file2.txt

The command above will first count the lines that are in the file called “file1.txt” and output them in the terminal and save them into a new file called “file2.txt”.

Send Tee Command Output To Other Commands

Now, we know that we can use the output in the terminal and pipe it into another command for processing. In this section, we will list the files found in a folder then write the output into a text file and pass the output to a third command, the grep command to identify the files with the string “py” found in them.

ls | tee file_name.txt | grep 'py'

Other Tee Command Operations

In most cases, tee command will overwrite the file with the output of the first command. However, it can be overridden using the -a option which is the append option such as the following command.

ls | tee -a file_name.txt

As for checking the version information, you may use this command.

tee --version

To learn more about the tee command syntax, use the following command for the documentation to assist you.

tee --help

An advantage of the tee command is for writing files with elevated privileges as usually within the highly secured VPS, most tasks are done by users with no privileges. This is important especially when we need to edit files that need admin privileges, using sudo command can be troublesome at times.

Was this article helpful?
Dislike 0
Previous: Disable Automatic Updates on Server 2016
Next: HOW TO: Remove (Delete) a User on CentOS 7
How can I help you today ?