Hi: How can I make lots(for example 5) of copies of a file.. (from the command line, not writing a script). I tried this but it didnt work..: $ for f in "file[1-5]" ; do `cp file $f` ; done and it made a copy called file[1-5] :-( Any pointers?? Thanks! Raul
* Raúl Gutiérrez Segalés (rau@campoalto.edu.py) [020205 08:10]:
How can I make lots(for example 5) of copies of a file.. (from the command line, not writing a script).
I tried this but it didnt work..:
$ for f in "file[1-5]" ; do `cp file $f` ; done
let n=5;while [ $n -gt 0 ]; do cp file "file$n" let "n -= 1" done -- -ckm
On Tue, 5 Feb 2002 13:18:18 -0300 (PYST) Raúl Gutiérrez Segalés <rau@campoalto.edu.py> wrote:
How can I make lots(for example 5) of copies of a file.. (from the command line, not writing a script).
I tried this but it didnt work..:
$ for f in "file[1-5]" ; do `cp file $f` ; done
and it made a copy called file[1-5] :-(
Any pointers??
Well 1 pointer is that you cannot have more than 1 file of the same name in any directory, that includes the directory name. So your loop must change the names to add an unique identifier, like x1,x2,x3,x4,x5 etc. So you can do: for f in 1 2 3 4 5; do `cp my.txt my.txt.$f`; done; -- $|=1;while(1){print pack("h*",'75861647f302d4560275f6272797f3');sleep(1); for(1..16){for(8,32,8,7){print chr($_);}select(undef,undef,undef,.05);}}
El Tue, 5 Feb 2002 13:18:18 -0300 (PYST) Raúl Gutiérrez Segalés <rau@campoalto.edu.py> escribio:
How can I make lots(for example 5) of copies of a file.. (from the command line, not writing a script). I tried this but it didnt work..: $ for f in "file[1-5]" ; do `cp file $f` ; done and it made a copy called file[1-5] :-(
Just yesterday I noted the existence of the "seq" command, that generates a sequence of numbers, something very useful for the kind of things you trying to do :) Try for n in `seq 5` ; do `cp file file$n` ; done
Hi Raul! Keep in mind that the shell expands any metacharacters (wildcards) before it is passed to the command. In this case, it **tried** expand "file[1-5]" but couldn't as there are no files in the current directory named file1, file2 and so forth. Therefore nothing gets expanded and the expression "file[1-5]" is assigned to the variable "f" with no expansion. Try: for f in 1 2 3 4 5 ; do cp file file${f} ; done I think that'll do what you need. However, Chris' example is great if you want to have a large number of copies or want to change the number of copies for different file. Regards, jimmo On Tuesday 05 February 2002 17:18, Raúl Gutiérrez Segalés wrote:
Hi:
How can I make lots(for example 5) of copies of a file.. (from the command line, not writing a script).
I tried this but it didnt work..:
$ for f in "file[1-5]" ; do `cp file $f` ; done
and it made a copy called file[1-5] :-(
Any pointers??
Thanks!
Raul
-- --------------------------------------- "Science has promised man power...But, as so often happens when people are seduced by promises of power, the price is servitude and impotence. Power is nothing if it is not the power to choose." Joseph Weizenbaum of MIT said in reference to Computers. --------------------------------------- The Great Linux-NT Debate: <http://www.jimmo.com/Linux-NT_Debate/index.html> --------------------------------------- NOTE: All messages sent to me in response to my posts to newsgroups or forums are subject to reposting.
participants (5)
-
Christopher Mahmood
-
Gustavo Muslera
-
James Mohr
-
Raúl Gutiérrez Segalés
-
zentara