LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 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 6, KDE Neon
Posts: 4,313

Rep: Reputation: 212Reputation: 212Reputation: 212
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: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

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: 225

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
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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,083

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



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

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

All times are GMT -5. The time now is 10:27 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