making multiple duplicate file copies using cp on 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.
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?
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
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.
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?
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
Possibly, some other files having extensions 001 and 002 already exist and their association are marked as "001 document (application/x-extension-001)".
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?
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.
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.
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] ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.