LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 07-21-2011, 10:45 AM   #1
rastavideo
Member
 
Registered: Jan 2003
Location: Texas
Distribution: Ubuntu
Posts: 66

Rep: Reputation: 15
making multiple duplicate file copies using cp on command line


I want to take a graphics file and make 10 copies of it to the same directory, each with 001, 002, or some such designation at the end of each file name so they have discrete files names. Is this possible using cp? If not, any suggestions?
 
Old 07-21-2011, 10:54 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Bash version 4 and above:
Code:
for num in {001..10}; do cp file file.$num; done
Bash version 3:
Code:
for num in {1..10}; do cp -p file file.$(printf "%03d" $num); done
 
Old 07-21-2011, 11:51 AM   #3
rastavideo
Member
 
Registered: Jan 2003
Location: Texas
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
Thanks for the suggestion. This is the way I wrote it out in the terminal, and it seems to execute but nothing is written in thedestination. What am I doing wrong?


scott@richmond:~$ #!/bin/bash for num in {001..010}; do cp /home/scott/switcher%20pix/JVC_yb_lower1.tga /home/scott/switcher%20pix/JVC_yb_lower1.tga.$num; done
 
Old 07-21-2011, 11:56 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Why did you put #!/bin/bash in front of the command line? It has sense only inside bash scripts as the very first line and tell the shell to parse commands with the specified interpreter. Instead, used on the command line it is just a comment, since the # characters at the beginning is interpreted like that and the rest of the line is ignored.
 
Old 07-21-2011, 12:27 PM   #5
rastavideo
Member
 
Registered: Jan 2003
Location: Texas
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
First I've ever done bash script. When I changed it, it worked fine. Thanks so much for that.

However, the first two files -- 001 and 002 -- identify themselves as "001 document (application/x-extension-001)" when viewed in properties and files 003 - 101 identify themselves properly as "TGA image (image/x-tga)". Any idea why?
 
Old 07-21-2011, 12:29 PM   #6
rastavideo
Member
 
Registered: Jan 2003
Location: Texas
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
Sorry for typo -- last batch of files should read "003 - 010"
 
Old 07-21-2011, 07:08 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Possibly something to do with your first attempt; delete the copies and do them again.
In this case, do use a bash script approach, then you can re-use it

Keep a note of these
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 07-21-2011, 09:55 PM   #8
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Possibly, some other files having extensions 001 and 002 already exist and their association are marked as "001 document (application/x-extension-001)".

OK
 
Old 07-22-2011, 12:28 AM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Yes. 001 and 002 are standard file extensions from HJSplit files.
 
Old 07-25-2011, 10:23 AM   #10
rastavideo
Member
 
Registered: Jan 2003
Location: Texas
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
There are no other files in the source/destination folder that end in the 001 series. I deleted all the files from the first attempt and ran the command again. Same result: first 2 files in the resulting series have the non-specific file description while files 003 - 010 have tga as a descriptor in Properties. Any suggestions?

If the process is not correctable, is there a way to change the file descriptor on the errant files by hand?
 
Old 07-25-2011, 12:10 PM   #11
Peverel
Member
 
Registered: May 2009
Location: Chelmsford, England
Distribution: OpenSuse 12.2 and 13.2, Leap 4.2
Posts: 128

Rep: Reputation: 24
Out of curiosity, 1 tried this on my system (OpenSuse 11.2), and found that the mechanism worked for all values, giving the correct properties. However, a bit of Googling shows that application/x-extension-001 does exist: it defines parts of a fax, subsequent parts being labelled .002,.003,... . Why it should stop at two I have no idea.
Sorry: colucix posted that last bit.

Last edited by Peverel; 07-25-2011 at 12:14 PM.
 
Old 07-25-2011, 12:32 PM   #12
rastavideo
Member
 
Registered: Jan 2003
Location: Texas
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
The mystery deepens: GIMP opens the oddly named files directly, and upon closing the files, displays the correct image icon in the directory folder that matches the properly named files. The real test will come when the files are read in sequence by a hardware device that will play them as a loop of tga images. I'll keep you posted.
 
Old 07-25-2011, 01:53 PM   #13
rastavideo
Member
 
Registered: Jan 2003
Location: Texas
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
Now this is really odd. The terminal mechanism worked well through the next 14 processes, with every process producing a batch of 20 new files, each appending tga to the file series. Until I got to file 123, which displayed its file type as "Lotus 1-2-3" spreadsheet! None of the other 320 resulting files showed this type. I've redone it a few times by altering the mechanism, but #123 also shows as a vnd file for Lotus.

Figuring out why these errors are so random is probably pointless now, but go ahead if you have an idea because I'd like to know. But more to the point now, how can I change the file type of the errant files to tga [ or x-tga as it displays in Properties] ?
 
  


Reply



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
How do i make multiple copies of a file in the command line? CoffeeKing!!! Linux - Newbie 17 09-06-2013 06:41 AM
Perl question: delete line from text file with duplicate match at beginning of line mrealty Programming 7 04-01-2009 06:46 PM
Adding values to a file and making a graph with it by command line (Spreadsheet?) Romanus81 Programming 4 07-02-2008 09:14 AM
duplicate the line of a text file to the same line powah Programming 4 01-11-2007 08:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:57 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration