Results 1 to 15 of 15
Thread: cp -r without overwrite prompt
-
01-12-2004, 11:22 PM #1Junior Guru Wannabe
- Join Date
- Oct 2001
- Posts
- 72
cp -r without overwrite prompt
I need to:
cp -r dirname/* dirname2/
and have it overwrite existing files and directories without asking me if it should each time. Can anyone tell me how I do that?
Thank you,
Chris
-
01-12-2004, 11:25 PM #2
Make that -rf
-
01-12-2004, 11:40 PM #3Junior Guru Wannabe
- Join Date
- Oct 2001
- Posts
- 72
That's easy! Thank you!
-
01-12-2004, 11:48 PM #4Junior Guru Wannabe
- Join Date
- Oct 2001
- Posts
- 72
oooppss, spoke to soon. I'm still getting:
cp: overwrite 'path/to/file'?
and there are hundreds of them.......
-
01-13-2004, 12:06 AM #5Web Hosting Master
- Join Date
- Aug 2000
- Posts
- 1,167
Open your .bashrc file with pico and look for the line that reads:
alias cp='cp -i'
and comment it out:
#alias cp='cp -i'
Log out, then log in again and you shouldn't get the prompt. This is a kind of safety net, so it's probably a good idea to put the command back as it was when you're done.
-
01-13-2004, 12:28 AM #6Junior Guru Wannabe
- Join Date
- Oct 2001
- Posts
- 72
That's the ticket Thank you both,
Chris
-
01-13-2004, 08:10 AM #7
Hmm, learned something here. Elements in the .bashrc file can't be overridden locally. Is there no way to do this for a single domain/user, so the entire server isn't affected?
Thanks alchiba.
-
01-13-2004, 09:49 AM #8Web Hosting Master
- Join Date
- Aug 2000
- Posts
- 1,167
/etc/skel/.bashrc is the shell template. Edit that to your liking and all subsequent new accounts will inherit those shell settings.
-
01-13-2004, 11:34 AM #9Web Hosting Master
- Join Date
- Aug 2000
- Posts
- 1,167
There's a .bashrc in the home directory for each user. If you edit that one it only affects that user.
-
07-11-2014, 12:20 AM #10New Member
- Join Date
- Jul 2014
- Posts
- 1
You can just use '/bin/cp -r' to do this without doing anything to the alias commands.
-
07-11-2014, 07:10 AM #11Web Hosting Master
- Join Date
- May 2012
- Location
- Linux World
- Posts
- 1,137
@ above, thats right. calling by full path is the widely used method.
Kevin Cheri : Senior Server Administrator / Freelancer : 13+ years Exp, reach me out for any help
Server Optimization Expert / Mysql Guru / Migration Specialist
Skype : lynxmaestro
Gmail : cheri.kevin@gmail.com
-
07-11-2014, 07:38 AM #12Digital Marketing Strategist
- Join Date
- Dec 2011
- Location
- Germany
- Posts
- 1,180
As others have confirmed already, simply using /bin/cp instead of "cp" will ignore the alias and therefore allow forcing to overwrite files. In scripts it is always recommended to use the full paths to avoid issues. And by the way instead of copying files with the cp command, I recommend to use rsync with "-av" parameters locally, because it will only copy/replace files that are actually different while keeping permissions and ownership (so syncing instead of copying), instead of copying everything over. This solution will be faster and safer imo.
➤ Inbound Marketing & real SEO for web hosting providers
✎ Get in touch with me: co<at>infinitnet.de
-
07-11-2014, 04:59 PM #13Web Hosting Guru
- Join Date
- Apr 2008
- Location
- Oregon
- Posts
- 295
You can also pipe. IE:
yes | cp -r asdf/* xyz/-Jacob
iWebFusion [AS397373] - 6 US datacenters offering shared, reseller, dedicated, VPS and Colo
California (x2) | Oregon | Iowa | North Carolina | Nevada
-
07-13-2014, 12:17 AM #14WHT Addict
- Join Date
- Mar 2011
- Posts
- 106
cp -af usually works too
Tara Roberts
www.whmxtra.com
-
07-15-2014, 04:54 AM #15Temporarily Suspended
- Join Date
- Mar 2014
- Location
- Prague
- Posts
- 132
Note that without -i you can possibly harm your system. Be careful what you type. I remember that once I ran rm -rf /* instead of rm -rf ./* :/