LinuxQuestions.org
Visit Jeremy's Blog.
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-06-2015, 07:10 PM   #1
Mike_Brown
Member
 
Registered: May 2015
Posts: 37

Rep: Reputation: Disabled
How to copy (save as) one file into multiple files (names are different)


I have a file temp.sh. I would like to save temp.sh as temp1.sh, Temp.sh, TEMP.sh, and a.sh. I am trying to use
Code:
cp temp.sh temp1.sh Temp.sh TEMP.sh a.sh
. But it does not work.
 
Old 07-06-2015, 07:31 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998
No, it doesn't. It doesn't work like that.

If you look at the error message it should be something like...

Code:
cp: target 'a.sh' is not a directory
cp will accept multiple sources but only one target. If there are multiple sources it will expect the target to be a directory.
 
1 members found this post helpful.
Old 07-06-2015, 07:46 PM   #3
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,252

Rep: Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559
You could try this:
Code:
echo -en "t1.sh\0t2.sh\0tn.sh\0"|xargs -0 -I '{}' cp /tmp/x.sh /tmp/'{}'
The args to echo are -e - use escape codes, -n - suppress newline.
Args to xargs are -0 use '0' as delimiter, -I '{}' replace '{}' with data read from stdin.
The \0 in the echo string inserts a 0, the byte NOT the character into the string.
 
Old 07-06-2015, 08:24 PM   #4
Aia
Member
 
Registered: Jun 2006
Posts: 66

Rep: Reputation: 21
Would a simple loop do?

Code:
for f in temp1 Temp TEMP a; do
    echo "cp temp.sh ${f}.sh"
done
Remove the echo and quotes if satisfied.

Last edited by Aia; 07-06-2015 at 08:30 PM. Reason: correction of question
 
Old 07-06-2015, 08:26 PM   #5
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,252

Rep: Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559Reputation: 559
That's the beauty of linux if you dont like one solution just hang around another one will be along in a moment.
 
  


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
[SOLVED] Copy content of a file into multiple files shivaa Linux - Newbie 6 10-13-2012 12:21 PM
Xfce: Save Page As: single file vs multiple files. stf92 Linux - Newbie 1 11-28-2010 08:20 AM
[SOLVED] copy lines from multiple files to one file using sed -w cruzdelsur Programming 12 08-26-2010 09:24 AM
copying multiple different files in different directories with identical file names nickleus Linux - Software 4 03-09-2006 02:25 PM
copy multiple files into one file HelpPlease Programming 2 12-09-2003 03:36 PM


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

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration