LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do i make multiple copies of a file in the command line? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-make-multiple-copies-of-a-file-in-the-command-line-665322/)

CoffeeKing!!! 08-25-2008 03:14 PM

How do i make multiple copies of a file in the command line?
 
I want to make multiple copies of a file using the command line in one command.
Is there a way I can do it where the files will be named automatically without having to type file(1) file(2) file(3)?

trickykid 08-25-2008 03:36 PM

Code:

for FILE in `seq 1 10`; do cp file file$FILE; done
This would cp file as file1 .. file10 if that's your goal, to add a number to each of the copies.

CoffeeKing!!! 08-25-2008 03:45 PM

thanks but, isn't there a more regular variation of a command line tool?

trickykid 08-25-2008 03:50 PM

Quote:

Originally Posted by CoffeeKing!!! (Post 3259437)
thanks but, isn't there a more regular variation of a command line tool?

What exactly are you looking for?

CoffeeKing!!! 08-25-2008 05:24 PM

I've used tee to copy files. I just have to manually enter the file numbers myself.

me@me:~/Desktop$ cp wavotmp3.sh | tee wavotm31.sh wavotmp32.sh wavotmp33.sh

and I get:

cp: missing destination file operand after `wavotmp3.sh'
Try `cp --help' for more information.



The files show up but, I get that error. Does anyone know why?
I'm looking for something similar to similar to tee or cp so I don't stray to far from novice commands for now.

umarzuki 08-25-2008 07:04 PM

Quote:

Originally Posted by CoffeeKing!!! (Post 3259524)
I've used tee to copy files. I just have to manually enter the file numbers myself.

me@me:~/Desktop$ cp wavotmp3.sh | tee wavotm31.sh wavotmp32.sh wavotmp33.sh

and I get:

cp: missing destination file operand after `wavotmp3.sh'
Try `cp --help' for more information.



The files show up but, I get that error. Does anyone know why?
I'm looking for something similar to similar to tee or cp so I don't stray to far from novice commands for now.

i see that wavotm31.sh wavotmp32.sh wavotmp33.sh have similarities in prefix. Why not
Code:

cp wavnotm3* .
*copy all files with prefix wavnot3 here. With cp you must have option and/or parameter, source then destination.

CoffeeKing!!! 08-25-2008 07:58 PM

Thanks umarzuki but, that won't do it. I just want to be able to cp a file as many times as I want and have the comp number the copies for me.

kinda like saying: make me three copies of wavnot.sh Number them by yourself. I'm looking for something simpler than

for FILE in `seq 1 10`; do cp file file$FILE; done

syg00 08-25-2008 08:28 PM

Simple enough to create a script based on the above - pass file and count in as parms. Then it becomes as easy as something like "./copyit filename 10"

trickykid 08-25-2008 09:11 PM

Quote:

Originally Posted by CoffeeKing!!! (Post 3259645)
Thanks umarzuki but, that won't do it. I just want to be able to cp a file as many times as I want and have the comp number the copies for me.

kinda like saying: make me three copies of wavnot.sh Number them by yourself. I'm looking for something simpler than

for FILE in `seq 1 10`; do cp file file$FILE; done

I don't think it's going to get any easier than that. If you're copying a file from one original file, they all need to be copied from that original. Define more simpler cause that's as basic as it's gonna get, using a for statement.

If you're looking for something like:

./somecommand <options>

Then like the previous poster said, throw what I've given you in a script that takes parameters afterwards of what you need or want.

Tinkster 08-25-2008 09:18 PM

Code:

for FILE in {1..10}; do cp file file$FILE; done
;}

trickykid 08-25-2008 09:21 PM

Quote:

Originally Posted by Tinkster (Post 3259699)
Code:

for FILE in {1..10}; do cp file file$FILE; done
;}

Ah man, you made it so it's one less character.

So why not this:

Code:

for F in {1..3}; do cp file file$F; done
Now that's even shorter.. ;)

Tinkster 08-25-2008 09:30 PM

Quote:

Originally Posted by trickykid (Post 3259703)
Ah man, you made it so it's one less character.

Code:

$ echo '`seq 1 10`'|wc -c
11
$ echo '{1..10}'|wc -c
8

/me ducks and covers ....

But the point is that it doesn't invoke an
external command (seq).

trickykid 08-25-2008 09:51 PM

Quote:

Originally Posted by Tinkster (Post 3259709)
Code:

$ echo '`seq 1 10`'|wc -c
11
$ echo '{1..10}'|wc -c
8

/me ducks and covers ....

But the point is that it doesn't invoke an
external command (seq).

Ah, when I said one less character, I wasn't counting the spaces but the two dots compared to my seq command. ;)

CoffeeKing!!! 08-25-2008 10:53 PM

Thanks a lot folks.

I've only written one script before. So, this will be fun. But, I also don't even understand the code very well. In fact, I have no idea how I would write this script.

Could one of you give me more help on writing a script that would except number of copies as a variable. I can't even tell if "File" or "FILE" represent variables of the name of the file I want to copy.

The craziest part of this is that I'm trying to figure out how to do this just so I can make useless scripts and learn how to adjust their permissions proficiently.

Tinkster 08-25-2008 11:06 PM

In the snippet above FILE is a variable, and file is the
thing you want to copy all over the place. What it does
is to produce a sequence of numbers from 1 to 10, and
then copy file to file${FILE} (where ${FILE} is replaced
with the number from 1 to 10) for each iteration of the
for loop.


All times are GMT -5. The time now is 07:50 AM.