Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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 have a single file (a PDF) and I want to have lots of identical copies in the same folder (200 would be nice) named file-001, file-002 etc.

How do I do it?

share|improve this question
No, it is for error correction. – Tim Aug 26 '14 at 12:58
The _ is a typo I hope? – Rinzwind Aug 26 '14 at 13:06
@Rinzwind yeah! that could be interesting - pick a random character for each? :p – Tim Aug 26 '14 at 13:07
@Tim: Well, to generate a random "_" or "-" you can printf "%s\n" "$(cat /dev/urandom | tr -dc '_-' | fold -w 1 | head -n 1 )" :-P (and be warned that is a can of worms, because echo - is one of this corner cases...) – Rmano Aug 27 '14 at 8:38
@Rmano I'll stick with - I think :P – Tim Aug 27 '14 at 8:39
up vote 19 down vote accepted

You could do something like

< file tee file-{001..200}

however if the medium becomes unreadable it will not matter how many copies are on it - fundamentally backups require diversity.

Note that tee writes its standard input to standard output as well as to each of the given files - for large files, or for files containing binary data or other special characters that may interfere with your terminal settings, you will probably want to dump standard output to the bit bucket

< file > /dev/null tee file-{001..200}
share|improve this answer
tee file-{001..200} < file >/dev/null looks for me more legibly. See this almost duplicate answer: How to copy a file to multiple folders in Terminal? – Radu Rădeanu Aug 26 '14 at 18:35

This is the classic case where shell tricks help a lot.

for i in {000..199}; do cp file file-$i; done

And I know it's a joke, but if you want a random _ or - separating the number from the name you can use:

for i in {000..199}; do 
    cp file file$(cat /dev/urandom | tr -dc '_-' | fold -w 1 | head -n 1 )$i; 

(multiple line to help readability...)


share|improve this answer
What if I wanted every prime number to be a _ and every non prime to be -? 1 is not prime, and you pick for 0! :P Jokes! – Tim Aug 27 '14 at 18:07

To make a single duplicate of a file you probably know that you can use cp:

cp file file-001

Now, to make more duplicates to a file, you can combine cp with xargs. In your case:

echo file-{001..200} | xargs -n 1 cp file

will copy file to file-001, file-002,... ,file-200. See man xargs for more info.

share|improve this answer

As always, the python truck comes late, but:

make it executable, drag it over a terminal window, drag the file to copy over the terminal window and set the number of copies:

script file number_ofcopies

The number of leading zeros is set automatically, the files are named file_001.pdf, file_002.pdf, with the filenumbers placed before the extension.

The script:

#!/usr/bin/env python3

import sys
import shutil

orig = sys.argv[1]; n = sys.argv[2]; size = len(str(n)); out = (orig[:orig.rfind(".")], orig[orig.rfind("."):])
for item in [out[0]+"_"+(size-len(str(item)))*"0"+str(item)+out[1] for item in range(1, int(n)+1)]:
    shutil.copyfile(orig, item)
share|improve this answer
Yeah, I tried with python earlier, but didn't like the inelegance... I typically go for python :) – Tim Aug 26 '14 at 14:00
@Tim It must be the font of the code on this site that hinders the prettyness of the python code :) – Jacob Vlijm Aug 26 '14 at 14:22
There are several ways to make this. – Braiam Aug 27 '14 at 11:24

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.