Cp and create files as {,.bak}


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cp and create files as {,.bak}
# 1  
Old 06-18-2013
Linux Cp and create files as {,.bak}

Hello Guys,

As the perefect lazy administrator was wondering if is possible to create several files from one instance as the quick tip of doing this using "cp" ;


$ cp demofile demofile.bak
or
$ cp demofile{,.bak}
$ls
demofile.bak

Something like the following e.g. using "touch" ...

v1ct0r$ touch test{1..8}.txt
v1ct0r$ ls
test1.txt test2.txt test3.txt test4.txt test5.txt test6.txt test7.txt test8.txt

...my try;

v1ct0r$ touch uno
v1ct0r$ cp uno{,3..4}
v1ct0r$ ls
uno uno3..4

...my desire output:
uno uno3 uno4

Thanks! Smilie
# 2  
Old 06-18-2013
The 'tee' command can do nearly that.

Code:
tee uno{3..4} < inputfile

It will also print to stdout.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-18-2013
What you're attempting is not possible because when there are more than 2 arguments cp treats the last as a directory.

Regards,
Alister
# 4  
Old 06-18-2013
Quote:
Originally Posted by alister
What you're attempting is not possible because when there are more than 2 arguments cp treats the last as a directory.

Regards,
Alister
Exactly... what I thought in first place, but as the cp test{,.bak} is one argument came to my mind that idea... nevertheless im on the journey to find something similar.. thinking in doing "for i in blablabla" .... but no.

My best, Smilie
# 5  
Old 06-18-2013
Please see my post above. tee can create multiple files from one source.
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 06-18-2013
Code:
echo demofile{,.bak}

works in bash, ksh, zsh (and in csh)
Code:
echo test{1..8}.txt

works in bash and zsh only.
But the combination
Code:
echo uno{,3..4}

does the {,} expansion only.
In your cp example the last argument must be a destination directory. (There are a few old cp versions that really copy all files to a destination file.)
This User Gave Thanks to MadeInGermany For This Post:
# 7  
Old 06-18-2013
Quote:
Originally Posted by Corona688
The 'tee' command can do nearly that.

Code:
tee uno{3..4} < inputfile

It will also print to stdout.
Hello,

yeah... now I was trying replicating .mov ( video files ) having a lot encoded output however it does the "copy" and its not corrupted.

v1ct0r$ tee 130410_22899_a{1..2}.mov < 130410_22899.mov

##############
ftypqt qt ??free
fver,sin084G0295GY-HM700finfCvinf
ainf"0buid
CؑQNU???O?B0pphd Pt4 Q@??????@einf~?skipPrtmdX??????fD???Ƞ?efreemdacinf%?
?ؑQNU???O?B?pinf<??????fD??????f???????gD??????g???????hD??????h???????iD??????i???????@E??????@???? ???AE??????A???????BE??????B???????CE??????C???????DE??????D???????EE??????E???????FE??????F???????G E??????G???????HE??????H???????IE??????I???????PE??????P???????QE??????Q???????RE??????R???????SE??? ???S???????TE??????T???????UE??????U???????VE??????V???????WE??????W???????XE??????X???????YE??????Y ???????`E??????`???????aE??????a???????bE??????b???????cE??????c???????dE??????d???????eE??????e??pp fc<?j??c????5?@^D???c??`L?|??`M??K? ?a?^?`?z?`M= F?? ??`Mv
k?`N?
?{? ?; ????c?
8???u Է?@V3
???`J??9?`U(? ޵???`P V??`U???? ق}8??md???@V02/??[?p?`L]??`Q???? ?=?_?`NXԅ?`T"?? ?
?y?`P?N??`S
??? ??v???b????@S???????`MaA??`QO?T? өJ?`Swlj?`W? ????`UZA??`[?8? ?Dr???k?!???@X?"!??U???`K.#P??`O?#?? ?9"y??`R?$?9?`U?%
?? ?/#?
?`T?&1??`S?&?)? ?#%b???0?1?2?3?4?5?6?7?8?9?:?;?<?=?>???@?A?B?C?D?E?F?G?H?I?J?K?L?M?N?O?P?Q?R?S?T?U?V?W?X?Y?Z?[?\?]?^?_?`?a?b?c?d?e?f?g?h?i?j?k??$?????;??#???????T???????'??U????L????????????S?????6???!????'S??8???? ??????k???t?g???
?????qx???
?????6???g????!??????1???l???????????9??????????????^??H??&????????>??????????U??????????????0?????? ?c???i??????????????????Y?????u??&???q???~?????????????m???-???8??+????????W??Z?????H??!??:???????????K?????3??S?????????^????????????????Q????????????????????? ?A???g???u???????????;?????#?????????{?????????????????????????V???????*?????????????????
?????????????????4???????o??Z??@??0?????+?????x?????t??-???????D???? (?? S?? ?????Q?????L????????????????????????????????????????????????????`???$??? ??????-???'???????????5??????????????????????l???????????????????????
???????????????[???????????9????????n???????????r??R??@????????
######


Great!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create several files from one

good morning friends I have a problem , I have a file with 2 million records, but that can be variable, I need to split that file and drop several files in 500,000 thousand records, someone can help me with some unix shell code thank you!!! (7 Replies)
Discussion started by: tricampeon81
7 Replies

2. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

3. Shell Programming and Scripting

Create multiple zip files each containing 50 xml files.

Hi, Is there a direct command or need to write a shell script for following requirement? Everyday a folder is populated with approx 25k to 30k xml files. I need to create multiple zip files in the same folder each containing 50 xml files. The last zip file may or may not contain 50 xml files.... (6 Replies)
Discussion started by: Rakesh Thobula
6 Replies

4. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

5. Shell Programming and Scripting

How to create multiple files?

HI, I would like to create the files as file1.txt file2.txt file3.txt ...... ....... ....... filen.txt in a single unix command, i dont want to use the loops. n is user specific Kindly help me in this. THank you Jagadeesh (2 Replies)
Discussion started by: jagguvarma
2 Replies

6. UNIX for Dummies Questions & Answers

cp times.csv{,.bak} -> makes a copy with *.bak extension. How this works?

Hi cp times.csv{,.bak}makes a copy with *.bak extension. How this works? Whats the gimmick here? Can't google special characters (1 Reply)
Discussion started by: slashdotweenie
1 Replies

7. Shell Programming and Scripting

Script to create files

Requirement:- SQLs select name from v$datafile; select name from v$controlfile; select name from v$tempfile; select MEMBER from v$logfile; These sqls has to run in one script and o/p of each sql has to write in seperate files.But the o/p is like if we issue select name from... (2 Replies)
Discussion started by: Sanal
2 Replies

8. UNIX for Dummies Questions & Answers

Create individual tgz files from a set of files

Hello I have a ton of files in a directory of the format app.log.2008-04-04 I'd like to run a command that would archive each of these files as app.log.2008-04-04.tgz I tried a few combinations of find with xargs etc but no luck. Thanks Amit (4 Replies)
Discussion started by: amitg
4 Replies

9. UNIX for Dummies Questions & Answers

on how to create files

hi guys! i want my user to create some new files in a directory: i would like the user to choose a file name and then to create some kind of user friendly utility that makes my user write what he/she wants in the file and then save it in the chosen directory. let's say that in my programme i... (2 Replies)
Discussion started by: fiol73
2 Replies
Login or Register to Ask a Question