Unix Shell - copy files using ksh shell script

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2004 > copy files using ksh shell script





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author copy files using ksh shell script
Anand

2004-05-19, 7:52 am

I want to copy more than 10000 file from one source and put it into
other destination. (but only by using Ksh shell script)
Michael Tosch

2004-05-19, 7:52 am

In article <13d31bbd.0405190241.2daffed2@posting.google.com>, versatile_anand@yahoo.com (Anand) writes:
> I want to copy more than 10000 file from one source and put it into
> other destination. (but only by using Ksh shell script)


echo "cp sourcedir/* destinationdir" | ksh


--
Michael Tosch
IT Specialist
HP Managed Services Germany
Phone +49 2407 575 313
Mail: michael.tosch:hp.com


ycl

2004-05-19, 7:52 am

If you want to move the files from the ~/old_dest to the ~/new_dest
direcotry:

cd ~/old_dest
tar cvf - * | (cd ~/new_dest;tar xvf -)

-ycl
Chris F.A. Johnson

2004-05-19, 7:52 am

On 2004-05-19, Anand wrote:
> I want to copy more than 10000 file from one source and put it into
> other destination. (but only by using Ksh shell script)


cp source/* destination

If you run into "Argument list too long" (I didn't have a problem
with 10,000 files, but I did with 20,000):

printf "cp \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" destination\n" source/* | ksh

Put in as many instances of \"%s\" as you like.

--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Stephane CHAZELAS

2004-05-19, 7:52 am

2004-05-19, 11:24(+00), Chris F.A. Johnson:
> On 2004-05-19, Anand wrote:
>
> cp source/* destination
>
> If you run into "Argument list too long" (I didn't have a problem
> with 10,000 files, but I did with 20,000):
>
> printf "cp \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" destination\n" source/* | ksh
>
> Put in as many instances of \"%s\" as you like.


Only if "printf" is a builtin of your shell which is not always
the case. And you'll run into troubles for filenames containing
double quotes.

you could do:

ksh -c '
set -- /source/*
while :; do
cp "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" /dest
(( $# > 9 )) && shift 9 || break
done'

--
Stephane
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com