I have one file (lets call it file1.xyz) that I want to use as a template to work on. I need to copy the contents of file1.xyz so that they replace the contents of the other files - file2.xyz, file3.xyz, file4.xyz, file5.xyz.....file70.xyz whilst keeping the original file name.

I have tried using:

cp file1.xyz *.xyz

The files are all in the same directory and I don't want to append them to each other.

This has not worked, how can I solve this problem?

  • Blindly copy it to all other "fellow" files inside a directory? Commented Mar 6, 2017 at 16:54

4 Answers 4


With zsh:

cat $f[1] > $f[2,-1]

That writes all output files in parallel though (as if using tee) which means that doesn't scale well to large number of files.

With any Bourne-like shell (including zsh and bash), you could always do:

set file*.xzy
source=$1; shift
for dest do cp "$source" "$dest"; done

Here's a one-liner that would create the files in your example:

for i in {2..70}; do cp file1.xyz file$i.xyz; done
  • 1
    Since the question has a Bash tag, you can also substitute `seq 2 70` with {2..70}. Commented Mar 6, 2017 at 22:43

The simplest way you can do by tee command

cat file1.xyz | tee *.xyz >/dev/null
  • This does not create the files file2.xyz through file70.xyz
    – cherdt
    Commented Mar 6, 2017 at 17:17
  • Author is asking about to replace the content of file,so i thought the file is already there Commented Mar 6, 2017 at 17:19
  • I see, you're right -- the OP does imply that the other files are already there. Your solution accomplishes that.
    – cherdt
    Commented Mar 6, 2017 at 17:32
echo file{2..70}.xyz | xargs -n 1 -t cp file1.xyz

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .