0

is there any way to add the current date when using tee? For example:

ls -al | tee someFile.txt

prints something along these lines:

== 23.10.2014 - 23:23:23 ==
...
Whatever the ls returned
...

It has to be done as a single command. Thanks!

ruben1691
  • 353
  • 3
  • 20

2 Answers2

1

For any command:

<command> | tee -a <filename>

OR

<command> | tee --append <filename>

Yakir GIladi Edry
  • 2,511
  • 2
  • 17
  • 16
0

It looks like what you're actually asking for is prepending, not appending.

{ echo "some prefix"; ls -al; } | tee someFile.txt

If you wanted to append a message, though, the syntax is exactly what you'd expect given the above:

{ ls -al; echo "some suffix"; } | tee someFile.txt
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • You are right I meant prepend. although it doesn't fully solve my problem, your answer is correct for the case I explained. I have opened a new question [here](http://stackoverflow.com/questions/26542882/prepend-message-to-rsstail) to solve my problem. Thanks! – ruben1691 Oct 24 '14 at 06:55