Title: cp command problems forcing overwrite using cp command
Description: cp command problems forcing overwrite using cp command Linux
Tags: cp, command, problems, forcing, overwrite, using, cp, command
Info: This Post Has Been Viewed 21481 Times SinceFri Jan 25, 2008 3:37 pm Author hostman With 18 Replies #5685

cp command problems forcing overwrite using cp command

today i was trying to copy a many files and when i send this command:

Command:

cp -rf /this/file /to/this/file


i get this prompts:

Command:

cp: overwrite '/this/file /to/this/file' ?


when i look at the man pages for cp it says:

-f, --force
if an existing destination file cannot be opened, remove it and
try again


so it shouldn't ask me, so i found out that de defaults on the dedicated linux server we got from www.webune.com has cp as alias. so if you having this same problem, then run this command to see your alias:

Command:
alias


OUTPUT:
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

as you can see, i do have an alias with cp

so how do you overwrite without prompt?
what i need to do is remove that cp alias witht he unalias command so i send this coommand:
Command:
unalias cp


so now when you do the alias command, you wont see the cp alias anymore

so what happens if your not the admin or dont have access to root, then you can run an unaliased cp command, try

Command:
$ /bin/cp -rf /this/file /to/this/file


hope this helps..

thanks for the guys at www.webune.com for their support on this question

Comments (18)
View Top Comments
Leave Your Comments...
#1
copy:
4 years ago
#38170
copy Fri Jan 25, 2008 3:39 pm
i recommend that isp's or unix systems with users who may be unfamiliar with unix setup the following aliases:

clr clear
cls clear
copy cp -i
del rm -i
delete rm -i
dir ls -alg
home cd ~
ls ls -f
md mkdir
move mv -i
pwd echo $cwd
type more
#2
Osman:
3 years ago
#70774
Osman Tue Sep 16, 2008 2:44 am
it did helped. thank you
#3
Chad:
3 years ago
#89275
Chad Thu Jan 08, 2009 1:53 pm
i was wondering why the silly box kept insisting on permission to 'cp' everything! thank you ever so much for the great tip!
#4
Dany:
3 years ago
#97273
Dany Mon Mar 16, 2009 1:44 am
or you can use \ in front of cp -f <source> <destination> command which will temporarly disable the alias.
#5
Fletch:
2 years ago
#105014
Fletch Mon Jun 01, 2009 11:25 am
or

yes n | cp -rf
#6
Sia:
2 years ago
#119436
Sia Tue Nov 03, 2009 5:14 am
nice one, thanks for that. pretty sure debian doesn't have tha alias by default. i'm kinda new to centos, and this was bothering me.
#7
os3009:
2 years ago
#126719
os3009 Mon Jan 25, 2010 10:37 pm
thanks.. very useful tip
i tried every step and worked fine
#8
Oleg:
2 years ago
#129947
Oleg Mon Mar 15, 2010 6:53 am
Thanks a lot! I've been wondering why would it ask me all the time to overwrite or not to overwrite the file. I had the same alias so thanks a lot again for the tip!
#9
g33kinfo:
2 years ago
#129999
g33kinfo Tue Mar 16, 2010 1:30 am
you can also add a \ in front of the command to temporarily disable the alias...

\cp -rf /this/file /to/this/file

g33kin
#10
maggo:
2 years ago
#131655
maggo Mon Apr 12, 2010 1:46 am
- at - g33kinfo

the command

\cp -rf /this/file /to/this/file

doesn't work on my machinse centos 5.4

any ideas?
#11
Mamun:
1 year ago
#141653
Mamun Wed Aug 11, 2010 6:11 am
I want to dont show overwrite commend for cp.

So what i do now.

Overwrite?
#12
John:
8 months ago
#164098
John Wed Aug 10, 2011 12:48 am
I know this topic is old but you can also use 'cp'.
#13
talha:
8 months ago
#164135
talha Wed Aug 10, 2011 8:31 am
it worked thank you for your sharing
#14
Georg:
6 months ago
#168490
Georg Mon Oct 17, 2011 7:50 pm
Thanks it helped!
#15
Ms:
5 months ago
#170177
Ms Wed Nov 16, 2011 9:34 pm
Great information, Thank you!!
#16
Frank:
5 months ago
#170203
Frank Thu Nov 17, 2011 8:29 am
You da man!!!!
#17
meh:
4 months ago
#171300
meh Mon Dec 05, 2011 9:41 am
love the layout of your instructions. clear and concise!
#18
Praxis:
1 minute ago
#181389
Praxis Sat Apr 21, 2012 5:06 am
Yet another customer served, the '\cp -f' option worked a charm on Debian.
Leave Your Comments...
Share
| More