LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Reply
 
Search this Thread
Old 08-25-2008, 03:14 PM   #1
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Rep: Reputation: Disabled
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)?
 
Old 08-25-2008, 03:36 PM   #2
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
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.
 
Old 08-25-2008, 03:45 PM   #3
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Original Poster
Rep: Reputation: Disabled
thanks but, isn't there a more regular variation of a command line tool?
 
Old 08-25-2008, 03:50 PM   #4
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally Posted by CoffeeKing!!! View Post
thanks but, isn't there a more regular variation of a command line tool?
What exactly are you looking for?
 
Old 08-25-2008, 05:24 PM   #5
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-25-2008, 07:04 PM   #6
umarzuki
Member
 
Registered: Aug 2008
Distribution: Debian
Posts: 61

Rep: Reputation: 15
Quote:
Originally Posted by CoffeeKing!!! View Post
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.
 
Old 08-25-2008, 07:58 PM   #7
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Original Poster
Rep: Reputation: Disabled
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
 
Old 08-25-2008, 08:28 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,354

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
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"
 
Old 08-25-2008, 09:11 PM   #9
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally Posted by CoffeeKing!!! View Post
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.
 
Old 08-25-2008, 09:18 PM   #10
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Code:
for FILE in {1..10}; do cp file file$FILE; done
;}
 
Old 08-25-2008, 09:21 PM   #11
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally Posted by Tinkster View Post
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..
 
Old 08-25-2008, 09:30 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Quote:
Originally Posted by trickykid View Post
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).
 
Old 08-25-2008, 09:51 PM   #13
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 199Reputation: 199
Quote:
Originally Posted by Tinkster View Post
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.
 
Old 08-25-2008, 10:53 PM   #14
CoffeeKing!!!
Member
 
Registered: Mar 2008
Posts: 117

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-25-2008, 11:06 PM   #15
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My error in mkisofs command to make a command line iso mg92865 Linux - Newbie 1 06-20-2008 11:43 AM
[SOLVED] How can I make an .iso file from a CD or DVD using the command line? rm_-rf_windows Linux - General 3 06-20-2007 08:29 AM
Multiple Command-Line Programs skibud2 Linux - Software 1 03-18-2007 06:17 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM
Multiple tty in command line tearinox Linux - General 2 02-12-2004 10:28 AM


All times are GMT -5. The time now is 08:27 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration