86

How to write a string to file and to stdout on console?

If I do

echo "hello" > logfile.txt

I view only hello in logfile.txt but how can I write hello also on console of Linux?

Federico Zancan
  • 4,846
  • 4
  • 44
  • 60
Catanzaro
  • 1,312
  • 2
  • 13
  • 24

2 Answers2

108

Use the tee command:

echo "hello" | tee logfile.txt
Biffen
  • 6,249
  • 6
  • 28
  • 36
47

You can use >> to print in another file.

echo "hello" >> logfile.txt
SuperNova
  • 25,512
  • 7
  • 93
  • 64