Tee Command Usage Examples
Tee command is used to store and view (both at the same time) the output of any other command.
Tee command writes to the STDOUT, and to a file at a time as shown in the examples below.
The following command writes the output only to the file and not to the screen.
The following command (with the help of tee command) writes the output both to the screen (stdout) and to the file.
The following command will take a backup of the crontab entries, and pass the crontab entries as an input to sed command which will do the substituion. After the substitution, it will be added as a new cron job.
- $ crontab -l | tee crontab-backup.txt | sed 's/old/new/' | crontab –
By default tee command overwrites the file. You can instruct tee command to append to the file using the option –a as shown below.