This question already has an answer here:

I have 5 files called file1, file2, file3, file4, file5, . I am attempting to run the following command echo "contents" >> file{1,2,3,4,5}. I get the following error when I run this command; -bash: file{1,2,3,4,5}: ambiguous redirect. My goal is to echo some text to multiply files in one command. How can I achieve this? Thanks in advance.

marked as duplicate by don_crissti, jayhendren, Community Dec 13 '16 at 21:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You can't redirect to multiple files. Instead, use tee -a (-a for "append", since in your question you use the appending redirect operator >>):

echo "contents" | tee -a file{1,2,3,4,5}

Another option is to use zsh instead of bash, which can redirect to multiple files:

[birdsnest ~]% echo foo > /tmp/{foo,bar}
[birdsnest ~]% cat /tmp/foo 
[birdsnest ~]% cat /tmp/bar 

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