Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I write the same content to many text files by using cat or echo in only one command?

For example I want to write "hello" to file1 and file2. I tried:

echo "hello" >> file1 file2

but it didn't work. How can I do it?

share|improve this question
up vote 20 down vote accepted

Use tee to read from standard input and write to standard output and files.

echo "hello" | tee -a file1 file2

-a is the short (and portable/standard) for GNU tee's --append

share|improve this answer
Nice! tee help me solve the problems. Thank you Kanvuanza! – neo0 Oct 6 '12 at 7:31
You're welcome :) – Pedro Lacerda Oct 6 '12 at 7:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.