Book Image

Linux Shell Scripting Essentials

Book Image

Linux Shell Scripting Essentials

Overview of this book

Table of Contents (15 chapters)
Linux Shell Scripting Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Duplicating a stream using tee


In some cases, it's necessary to print an output on stdout and save an output in a file. In general, command output can either be printed or can be saved in a file. To solve it, the tee command is used. This command reads from the standard input and writes to both standard output and files. The syntax of tee will be as follows:

tee [OPTION] [FILE …]

The tee command copies the output to each FILE and also to stdout. The OPTIONS can be as follows:

Option

Description

-a, --append

This appends to the FILE instead of overwriting

-i, --ignore-interrupts

This ignores interrupt signals, if any

Writing an output to stdout and file: In general, to write an output to stdout and file, we will call the same command twice, with and without redirection. For example, the following command shows how to print an output on stdout and save it to a file:

$  ls /usr/bin/*.pl  # Prints output on stdout
/usr/bin/rsyslog-recover-qi.pl  /usr/bin/syncqt.pl
$  ls /usr/bin/*...