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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-16-2009, 08:26 PM
|
#1
|
|
Member
Registered: Jul 2008
Posts: 184
Rep:
|
How to copy files without overwriting?
How to copy files without overwriting?
I tried
but it still asking me…
|
|
|
|
02-16-2009, 08:41 PM
|
#2
|
|
Senior Member
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 2 / CrunchBang Linux 10 Statler / Easy Peasy
Posts: 4,287
|
If you use -u it will only overwrite an existing file if the source file is newer.
|
|
|
|
02-16-2009, 11:25 PM
|
#3
|
|
Member
Registered: Jul 2008
Posts: 184
Original Poster
Rep:
|
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...
|
|
|
|
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,592
Rep: 
|
Is there an alias set for cp to be cp -i?
|
|
|
|
02-17-2009, 03:13 AM
|
#5
|
|
Member
Registered: Aug 2008
Location: Beacon Bay, East London, South Africa
Distribution: Ubuntu
Posts: 30
Rep:
|
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.
|
|
|
|
02-17-2009, 03:32 AM
|
#6
|
|
Member
Registered: Aug 2008
Location: Yemen
Distribution: Fedora, CentOS, RedHat , OpenFiler, ESXI
Posts: 206
Rep:
|
Quote:
Originally Posted by Stephan_Craft
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.
|
|
|
|
02-17-2009, 04:02 AM
|
#7
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
|
|
|
02-17-2009, 05:28 AM
|
#8
|
|
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 3,965
|
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 |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 03:05 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|