How do i make multiple copies of a file in the command line?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)?
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'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.
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"
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.