I saved a template in ~/Templates that I use very regularly. How do I create new file with same template from terminal?

Now, I'm using with cp

cp ~/Templates/cf_temp ~/Desktop/new

I want to create multiple files at once with template.

Is there any better way?

  • What is "better" in your point of view? a shorter command with less flexibility? Since "cp ~/Templates/cf_temp" will always be the same you can create a function/alias where you can replace that by a single letter a ~/Desktop/new would then do the same or even a new where you also include `~/Desktop/~ into the function/alias – Rinzwind Dec 14 '20 at 17:55
  • @Rinzwind with cp I cannot create multiple at once, I should this to the question too. – Yelp Dec 14 '20 at 18:01
  • @Rinzwind Yes, creating alias was the idea but I thought there some command for this or touch would take template as parameter when creating files. – Yelp Dec 14 '20 at 18:03
  • If you want to write the same template to multiple files, you can either wrap cp in a loop, or use tee. See for example How can I copy content of one file into several other files in the command line? – steeldriver Dec 14 '20 at 18:22

Need a loop here:

for newfile in new1 new2 new3; do 
  cp ~/Templates/cf_temp ~/Desktop/"$newfile"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.