LinuxQuestions.org
Visit Jeremy's Blog.
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, 08:05 AM   #1
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 27

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, 08:13 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
-f WILL force an overwrite, it will never ask to confirm.
 
Old 01-19-2012, 08:16 AM   #3
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: rhel 5x,6.0,6.2, centOS 5x,6.0,6.2
Posts: 1,194
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, 08:19 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
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, 08: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, 08:38 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

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

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, 08:48 AM   #8
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 27

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, 08:49 AM   #9
deep27ak
Senior Member
 
Registered: Aug 2011
Location: Bangalore, India
Distribution: rhel 5x,6.0,6.2, centOS 5x,6.0,6.2
Posts: 1,194
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, 09:26 AM   #10
sscn
LQ Newbie
 
Registered: Jan 2006
Location: China
Distribution: Fedora
Posts: 27

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 09:44 AM.
 
Old 01-19-2012, 09: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, 09:56 AM   #12
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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, 10:04 AM   #13
Vi_rod
Member
 
Registered: Dec 2011
Posts: 42

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

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
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 11:17 AM.
 
1 members found this post helpful.
Old 01-19-2012, 11:24 AM   #15
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 01:41 AM
[SOLVED] Network manager overwrite resolvconf vpn data with eth0 data rein2red Debian 1 03-21-2010 03:14 PM
GUI Folder Overwrite pymehta Linux - Software 1 03-07-2005 11:18 PM
Copy and Overwrite jrdioko Linux - Newbie 2 06-29-2004 12:46 PM
overwrite directory copy medamnit Linux - Newbie 1 05-26-2002 01:09 PM


All times are GMT -5. The time now is 02:28 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration