Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to copy a file to 10 files. Say for example I have a E-mail message named test1.eml. I want 10 copies of the same file.

When I searched in internet, I came across this stackoverflow thread http://stackoverflow.com/questions/9550540/linux-commands-to-copy-one-file-to-many-files and followed the eval command mentioned by one of the community member 'knittl'.

eval 'cp test1.eml 'test{2..10}.eml';'

The above mentioned command worked and it met my requirements. Are there any other alternative/more elegant commands to achieve this, since the person who mentioned about eval command told it's kind of a dirty hack.

share|improve this question
Are you sure you want to copy the file (and it's content) or would some symlinks (or maybe even hard links) match your purpose? – max.haredoom Feb 29 at 22:11
up vote 11 down vote accepted

I would do something like for i in {2..10}; do cp test1.eml test$i.eml; done
Yet is more or less the same thing.

share|improve this answer
Thanks Svetlin and don_crissti. That's a simple and small solution. – dkarthik Feb 29 at 15:37
 tee >test2.eml test{3..10}.eml < test1.xml

would only read the source once and execute only one command. It might not be more efficient for large files and could encourage fragmentation as tee would write blocks of data in each output file in turn. It also creates files with permissions according to your current umask instead of partly or completely reproducing the original permissions as cp does depending on options.

If you want to save typing, just use zsh as your shell (that's where those {2..10} constructs come from btw)

 for f (test{2..10}.eml)cp test1.eml $f

Which is as short as your:

 eval 'cp test1.eml 'test{2..10}.eml';'

yet more intuitive/legible and more easily generalisable to file names with more problematic characters.

With zsh and assuming you've not disabled the multios option, you can also do:

<test1.eml >test{2..10}.eml

There, zsh does the tee internally and also invokes cat. So it's slightly less efficient than the tee approach.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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