32

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?

Pedro Lacerda
  • 1,021
  • 8
  • 17
neo0
  • 755
  • 2
  • 7
  • 7

1 Answers1

53

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

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Pedro Lacerda
  • 1,021
  • 8
  • 17