PDA

View Full Version : UNIX Copy command problem


mcbootus
11-18-2007, 05:28 AM
Hi all,

I have a linux server and regularly need to copy the contents of a cache folder into my master website folder. The problem is the destination folder contains exactly the same file names as the source folder and whatever copy command I try I am always left with an overwrite prompt message per item, but because there are over 1000 files I do not want to see an over write prompt, I just want a forced overwrite.

I have tried these two commands but I cannot avoid the overwrite prompt with these:

cp -rf /root/home/folder1/cache /root/home/folder2/cache

or

cp -rf /root/home/folder1/cache/* /root/home/folder2/cache


Does anyone know a way to avoid the overwrite prompt please?

Thanks in advance! :)

Bootus

mikeyp
11-18-2007, 07:52 PM
i would have thought that the -rf would have done what you want. Try doing an rm right before that

rm /root/home/folder2/cache/* | cp -rf /root/home/folder1/cache/* /root/home/folder2/cache

mgolvach
11-21-2007, 02:07 AM
Also, I know RedHat likes to include aliases for cp, mv and rm (to "cp -i," "mv -i" and "rm -i" respectively) so you're doing an interactive copy even when you're forcing it. I think you can find them in either /etc/profile or /etc/bashrc. If you remove these aliases, the problem should go away.

Just typing "alias" at the command line when you log in should show you these.

Hope that's helpful :)

, Mike

mcbootus
11-28-2007, 05:14 AM
Hi guys,

Thanks for the advice.

mikeyp - Currently I am doing the rm just before the copy but this has other complications which causes the copy to fail occasionally.

mgolvach - this sounds really promising - i suspected there was a server issue causing the cp to misbehave - let me try your suggestion and get back to you.

Thanks again!

:)

McB

mcbootus
12-09-2007, 07:44 AM
Thanks for the info guys - I got a solution!

Yeah there are aliases on the system, I tried to delete them but they seemed to come back. I found a quicker solution, you can override an alias by adding ' ' around the command - this will force any settings you specify over the alias.

Like this:

'cp' -rf /root/home/folder1/cache/* /root/home/folder2/cache

Works a treat!

Thanks again.

McB

mgolvach
05-07-2008, 11:27 PM
Nice :)

I never knew that. I got in the habit of putting

unalias rm
unalias cp
unalias mv

in all my .profiles and .bashrc's

Good show :)

, Mike