The tee
command is a quick way to create a text file or add text to
an existing text file. Suppose,
for example, that you want to create a file which contains the
name and phone numbers of your coworkers. You can use the tee
command as follows:
$ tee phone_list.txt
Bill O. -
808-555-9876
Bill O. -
808-555-9876
Fred P. -
808-555-6543
Fred P. -
808-555-6543
When the first
line is entered, the system searches for a file named phone_list.txt.
If the file exists, the system overwrites its contents with
the new information. If the file does not exist, it is created
and the content is written into it.
Each line
is entered by pressing the Return key. The line of text is duplicated
in the shell, showing you it has been written to the output file.
Use Control - c
to end the input of content.
The -a
option for the tee
command allows you to append data to a file without overwriting
the current contents.