Linux tee command - Copies standard input to each specified file

Linux tee command: Copies standard input to each specified file

Linux tee command Function Description

Use the tee command to copy the standard input to each specified file and display it to the standard output.

Main purpose: Use when you need to view the data content and output to a file at the same time.

Note:

  1. This command is in the GNU coreutils package, see man -s 1 tee or info coreutils 'tee invocation' for related help information.
  2. There is a caching mechanism that will output once every 1024 bytes. If input data is received from the pipeline, the buffer should be full before dumping the data to the specified file. If the file content is less than 1024 bytes, the buffer will be flushed once after receiving the data read from the standard input device, and the data will be dumped to the specified file.

Linux tee command Syntax

tee [Option] [File]

The meaning of each option in the command is shown in the following table.

Option Description
-a Append the content to the specified file instead of overwriting it
-i Ignore interrupt signals

Linux tee command Example

Copy the standard input to the /root/file file and display it to the standard output

[root@rhel ~]# tee /root/file
abc                               // Input characters
abc
def                               // Input character
def                               // Press the [Ctrl+d] key combination here

Append the contents to the specified /root/file file

[root@rhel ~]# tee -a /root/file
ghi                               // Input characters
ghi                               // Press the [Ctrl+d] key combination here

Input the output of cat to the standard output and fff file

cat /root/apidemos.com.txt|tee fff

Output:

Linux tee command

Pipeline process information to standard output (terminal) and overwrite it to a file

ps -ef |tee info_a.log info_b.log

Piping process information to standard output (terminal) and appending it to a file

ps -ef |tee -a info_a.log info_b.log
Like(2)

Related

Linux Login Logout Command
Linux login commandLinux logout commandLinux nologin commandLinux exit commandLinux sulogin commandLinux rlogin commandLinux poweroff commandLinux ctrlaltdel CommandLinux shutdown commandLinux halt commandLinux reboot commandLinux init commandLinux runlevel commandLinux telinit command
Linux File Management Command
Linux cat commandLinux tac commandLinux nl commandLinux more commandLinux less commandLinux head commandLinux tail commandLinux rev commandLinux fold commandLinux fmt commandLinux expand commandLinux pr commandLinux sort commandLinux uniq commandLinux cut commandLinux comm commandLinux diff commandLinux join commandLinux diff3 commandLinux cmp commandLinux colrm commandLinux paste commandLinux mkdir commandLinux tr commandLinux split commandLinux csplit commandLinux tee commandLinux unexpand commandLinux patch commandLinux awk commandLinux sed commandLinux od commandLinux pwd commandLinux cd commandLinux ls commandLinux dir commandLinux dirs commandLinux touch commandLinux rmdir commandLinux cp commandLinux mv commandLinux rm commandLinux install commandLinux tmpwatch commandLinux file commandLinux du commandLinux wc commandLinux tree commandLinux cksum commandLinux md5sum commandLinux sum commandLinux dirname commandLinux mkfifo Command
Cron Expressions
Cron Expression to Run Every Day at 12 PMUnderstanding Vue Cron ExpressionsUnderstanding JS Cron ExpressionsA Comprehensive Guide to Cron Expressions for Scheduled TasksUnderstanding Linux Cron ExpressionsUnderstanding Quartz Cron ExpressionsCron ExpressionCron Time ExpressionCron Expression ParsingCron Expression: Executing a Task Every SecondCron Expression for Every Minute ExecutionCron Expression to Execute Every 10 MinutesCron Expression: Executing Every HourCron Expression to Execute Once a YearCron Expression: How to Schedule a Task to Run Daily at Midnight?