1

I am unable to figure out how to properly pipe and tee to append to a range of files. Instead of manually typing them out

echo "help!" | tee >> file1 file2 file3

I am trying to figure out:

echo "help!" | tee >> ~/file*

I have tried one line commands and tried making a loop using ls, echo, and touch but I am still unsure how to pipe a list of files into tee.

3

You can use the -a flag to tee to tell it to append, so if you really have files that match ~/file* you can do

echo "help!" | tee -a ~/file*

or whatever list of files you actually want

If you don't already have those files as @steeldriver surmises, you could create, say, 5 files like

echo "help!" | tee -a ~/file{1..5}

to create file1 through file5

  • I think the OP may be looking for something like brace expansion (to create the files if necessary) rather than a simple file glob – steeldriver Jan 8 '16 at 16:34
  • @steeldriver ok, edited to include that case, thanks – Eric Renouf Jan 8 '16 at 16:36
  • @EricRenouf thank you! I tried the -ia earlier thinking that was the problem I must've been fat fingering something! – Ian Jan 8 '16 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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