Operating System - HP-UX
1839275 Members
4880 Online
110138 Solutions
New Discussion

copy files in directory that don't exist

 
SOLVED
Go to solution
Martin Corner
Advisor

copy files in directory that don't exist

Hi All,

Sorry for the stupid question, but it has been a long day at work in the UK.

I need to copy files from one directory to another, but if the file already exists on the destination directory then I don't want to overwrite.

I know this is simple but just can't seem to get it to work.

TIA
2 REPLIES 2
Mark Greene_1
Honored Contributor
Solution

Re: copy files in directory that don't exist

cp -i will ask before overwriting.

Hope your day goes better!

mark

the future will be a lot like now, only later
Pete Randall
Outstanding Contributor

Re: copy files in directory that don't exist

Sue,

A for loop should work. Something like

for i in /dirname/*
do
if [ ` ls -ld /newdir/$i | wc -l` -ne 1 ]
then
cp $i /newdir
fi
done


Pete

Pete