View the Most Wanted LQ Wiki articles.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-16-2009, 08:26 PM   #1
Registered: Jul 2008
Posts: 184

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

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

Rep: Reputation: 208Reputation: 208Reputation: 208
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
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
Senior Member
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
Is there an alias set for cp to be cp -i?
Old 02-17-2009, 03:13 AM   #5
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
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 216

Rep: Reputation: 32

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

Rep: Reputation: 657Reputation: 657Reputation: 657Reputation: 657Reputation: 657Reputation: 657
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
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,052

Rep: Reputation: 379Reputation: 379Reputation: 379Reputation: 379
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).


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 11:34 AM.

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