LinuxQuestions.org
Register a domain and help support LQ
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 02-16-2009, 08:26 PM   #1
Stephan_Craft
Member
 
Registered: Jul 2008
Posts: 184

Rep: Reputation: 30
How to copy files without overwriting?


How to copy files without overwriting?
I tried
Code:
cp –rf
but it still asking me…
 
Old 02-16-2009, 08:41 PM   #2
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 4
Posts: 4,297

Rep: Reputation: 205Reputation: 205Reputation: 205
If you use -u it will only overwrite an existing file if the source file is newer.
 
Old 02-16-2009, 11:25 PM   #3
Stephan_Craft
Member
 
Registered: Jul 2008
Posts: 184

Original Poster
Rep: Reputation: 30
the problm is that it's always asking if i want to ovewrite it... i need to insert crontab for my backups to copy only new files without asking...
 
Old 02-16-2009, 11:31 PM   #4
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,627

Rep: Reputation: Disabled
Is there an alias set for cp to be cp -i?
 
Old 02-17-2009, 03:13 AM   #5
dopla
Member
 
Registered: Aug 2008
Location: Beacon Bay, East London, South Africa
Distribution: Ubuntu
Posts: 30

Rep: Reputation: 16
It's possible that there is an alias of "cp -i" but then "-f" would override "-i". another possibliity is that you are writting to write-protected files and the system needs your confirmation. For the first case "cp -rf" should work fine (I simply bypass aliases by backslash eg "\cp -r"). For the second case, I'm not sure.
 
Old 02-17-2009, 03:32 AM   #6
maas187
Member
 
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 210

Rep: Reputation: 32
Question

Quote:
Originally Posted by Stephan_Craft View Post
the problm is that it's always asking if i want to ovewrite it... i need to insert crontab for my backups to copy only new files without asking...
why dont you just rename the file to a diffrent name.


example. keep the old file and rename it to todays date. like file_name_Fed_11 and so on.

you could keep a log of backups, instead of rewriting.
 
Old 02-17-2009, 04:02 AM   #7
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
To simply not overwrite files, you can use the -i option and add "< <(yes n)" to the end of the command. ( But any output including a prompt may cause a problem if you do this in cron. )

Also look at cp's backup options. This would allow copying and make backups of the old file.
 
Old 02-17-2009, 05:28 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Redirecting or even piping the output of "yes" into a cp -i command is a way, as jschiwal said. However, you might also consider to choose to a more advanced tool, like rsync (just an example, it might suit you or not for your purpose).
 
  


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
move files without overwriting files nathan2225 Linux - General 1 04-11-2008 04:01 PM
upload using FTP WITHOUT overwriting existing/newer files HyperBlade Linux - Software 1 04-05-2008 11:10 PM
How to copy without overwriting [KIA]aze Linux - Newbie 4 03-08-2007 07:42 AM
Please Help! Ubuntu keeps overwriting system files! ckr Ubuntu 2 07-13-2006 05:51 PM
php/ftp overwriting files.. prob. collen Programming 1 03-14-2005 04:56 AM


All times are GMT -5. The time now is 08:12 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration