LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-19-2012, 07:05 AM   #1
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 28

Rep: Reputation: 0
cp - how to copy data to an existed folder without asking overwrite?


Hi,

I want to copy everything in one folder "log" to an existed folder "logbackup" without asking me overwrite or not. Just overwrite it.

both "cp -a" and "cp -rf" need me to confirm overwrite or not.

Thanks in advance!

sscn
 
Old 01-19-2012, 07:13 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
-f WILL force an overwrite, it will never ask to confirm.
 
Old 01-19-2012, 07:16 AM   #3
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: RHEL 7.x, SLES 11 SP2/3/4
Posts: 1,195
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
try this
Code:
#rsync -rv /source/*  /destination/
 
1 members found this post helpful.
Old 01-19-2012, 07:19 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Check for aliases, you may have noclobber or interactive included transparently

Code:
$ alias
alias cp='cp -n'
 
1 members found this post helpful.
Old 01-19-2012, 07:37 AM   #5
kishore_ari
LQ Newbie
 
Registered: Apr 2011
Posts: 12

Rep: Reputation: 5
sscn,

check what is the output of the command alias. I think there might be an alias for cp like alias cp='cp -i', which is why cp -rf asking for confirmation.
 
1 members found this post helpful.
Old 01-19-2012, 07:38 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
unalias -a is useful in scripts
 
1 members found this post helpful.
Old 01-19-2012, 07:46 AM   #7
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 28

Original Poster
Rep: Reputation: 0
unalias -a works for me

After I use "unalias -a", cp -rf doesn't need to confirm overwrite.
 
Old 01-19-2012, 07:48 AM   #8
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 28

Original Poster
Rep: Reputation: 0
My alias output.

alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
 
Old 01-19-2012, 07:49 AM   #9
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: RHEL 7.x, SLES 11 SP2/3/4
Posts: 1,195
Blog Entries: 4

Rep: Reputation: 221Reputation: 221Reputation: 221
Quote:
Originally Posted by sscn View Post
After I use "unalias -a", cp -rf doesn't need to confirm overwrite.
try the command which I gave
 
1 members found this post helpful.
Old 01-19-2012, 08:26 AM   #10
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 28

Original Poster
Rep: Reputation: 0
Hi deep27ak,

I am trying rsync. To me, rsync is a big tool to be used in my case.

1) rsync efficiency is not better than cp command for new added stuff;
2) If logbackup folder has very big data like 40GB, the increament list created by rsync takes too much time.

I just need to copy new created logs to the backup folder.

Pls correct me if I am wrong on rsync.

Thanks a lot.

Last edited by sscn; 01-19-2012 at 08:44 AM.
 
Old 01-19-2012, 08:50 AM   #11
kishore_ari
LQ Newbie
 
Registered: Apr 2011
Posts: 12

Rep: Reputation: 5
sscn,

It's the other way round, rsync is better than cp, as rsync compares the checksum of the files and it's used even when syncing files across systems.

I suspect the alias cp is in your .bashrc or .bash_profile files, you can just uncomment that or remove so that cp -rf works without confirmation.
 
1 members found this post helpful.
Old 01-19-2012, 08:56 AM   #12
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Another trick is to simply respond yes.
cp -rf source/* /destination/ < <(yes y)

I'll sometimes use "< <(yes n)" to prevent overwriting files.
 
1 members found this post helpful.
Old 01-19-2012, 09:04 AM   #13
Vi_rod
Member
 
Registered: Dec 2011
Posts: 42

Rep: Reputation: Disabled
aliasing works!
 
Old 01-19-2012, 10:16 AM   #14
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by sscn View Post
Hi deep27ak,

I am trying rsync. To me, rsync is a big tool to be used in my case.

1) rsync efficiency is not better than cp command for new added stuff;
2) If logbackup folder has very big data like 40GB, the increament list created by rsync takes too much time.

I just need to copy new created logs to the backup folder.

Pls correct me if I am wrong on rsync.

Thanks a lot.
rsync is much better for backing up than cp, by far. Yes the increment list takes a long time on a big archive, but the advantage is rsync will ONLY copy over those files which have changed, whereas cp will overwrite everything, every time. If your disc has an 80MB/s write speed and you're backing up a 40GB archive, cp will take a minimum of 8-9 minutes. If it's a lot of small files, it could easily take upwards of 30 minutes or more. On the same operation, rsync may take 2-3 minutes to build up the increment list, but then it might only take 20 seconds to copy the changed files over, depending on how many have changed since the last backup. It's especially useful when backing up across a network connection, or the internet.

Last edited by suicidaleggroll; 01-19-2012 at 10:17 AM.
 
1 members found this post helpful.
Old 01-19-2012, 10:24 AM   #15
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by suicidaleggroll View Post
the advantage is rsync will ONLY copy over those files which have changed
It is even better than that. rsync detects the changes and copies only what actually has changed. If you have for example a large log-file and only a few lines have changed rsync will not copy the whole file, but only the changes.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy without overwrite prompt nanda22 Linux - Newbie 6 07-11-2011 12:41 AM
[SOLVED] Network manager overwrite resolvconf vpn data with eth0 data rein2red Debian 1 03-21-2010 02:14 PM
GUI Folder Overwrite pymehta Linux - Software 1 03-07-2005 10:18 PM
Copy and Overwrite jrdioko Linux - Newbie 2 06-29-2004 11:46 AM
overwrite directory copy medamnit Linux - Newbie 1 05-26-2002 12:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration