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! :b:

The 'tee' command can do nearly that.

tee uno{3..4} < inputfile

It will also print to stdout.

1 Like

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, :b:

Please see my post above. tee can create multiple files from one source.

1 Like
echo demofile{,.bak}

works in bash, ksh, zsh (and in csh)

echo test{1..8}.txt

works in bash and zsh only.
But the combination

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.)

1 Like

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
CQNU???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???????GE??????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??ppfc<?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?`Sw?`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!

I warned you it prints to stdout :stuck_out_tongue: Now you know what that means. To avoid that:

tee ...  > /dev/null