LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-16-2009, 07:56 AM   #1
basher400
Member
 
Registered: Mar 2005
Posts: 54

Rep: Reputation: 15
copying folder to another withtout overwritting the destinaion files


hi

I have 2 folders "source" and "destination".
some of the files at the "destination" are the same name as "source" and are newer than the ones at "source".

I need to copy all files in "source" and symbolic links and sub-folders and etc. to "destination" without overwriting anything at the "destination" folder even if the files are the same name , even if the files at the "source" folder are newer than the ones at "destination"

I have to do this via a shell script with 1 or 2 commands and can't be prompt to ask if I want to overwrite or not.

another obstacle : I can't use the rsync command, system administrator doesn't give me access to do so.

this is as close as I got so far:
Code:
cp -p -r -u /source/* /dest
the only problem right now is that the "-u" flag works as so (form the man):
Quote:
"copy only when the SOURCE file is newer than the destination file or when the destination file is missing"
and as mentioned: I don't want to overwrite even if the files at the "source" are newer.

Last edited by basher400; 07-16-2009 at 08:01 AM.
 
Old 07-16-2009, 08:21 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I think you simply have to give some of the files different names, but.... If the files you are copying are the same, then why would you need to keep two copies?

Last edited by pixellany; 07-16-2009 at 08:31 AM.
 
Old 07-19-2009, 12:53 AM   #3
basher400
Member
 
Registered: Mar 2005
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
If the files you are copying are the same, then why would you need to keep two copies?
i'm not sure I understand what you mean by that...

the files at the destination and the source are not the same.
some of them MIGHT have the same name but some of the files at the destination are newer.
also I can't give them different names...why should I ? I don't want to overwrite files at the destination folder at all

you know what...let me start with something simple:
is there a way to copy files from one folder to another without overwriting the files in the destination folder no matter if the files at the source are newer or whatever ?
OR
is there a way to set a list of files to exclude when copying one folder to another ?

Last edited by basher400; 07-19-2009 at 01:07 AM.
 
Old 07-19-2009, 04:38 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,910

Rep: Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026
You could try something along the lines of a

Code:
tar -C /sourcedir -cvf - * | tar -C /destdir -k -xvf -
-k = keep old files

The exact syntax may not be exactly right above, but you get the idea.
 
Old 07-19-2009, 08:32 AM   #5
basher400
Member
 
Registered: Mar 2005
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by GazL View Post
You could try something along the lines of a

Code:
tar -C /sourcedir -cvf - * | tar -C /destdir -k -xvf -
-k = keep old files

The exact syntax may not be exactly right above, but you get the idea.
this is getting closer.
i got a lot of "No such file" errors....
 
Old 07-19-2009, 08:47 AM   #6
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
rsync's -u option
 
Old 07-19-2009, 08:48 AM   #7
basher400
Member
 
Registered: Mar 2005
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by AlucardZero View Post
rsync's -u option
as I said in my first post, I can't use the rsync command
 
Old 07-19-2009, 09:54 AM   #8
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,910

Rep: Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026Reputation: 5026
Quote:
Originally Posted by basher400 View Post
this is getting closer.
i got a lot of "No such file" errors....
Ahh, ofcourse. The * wildcard will be expanded to filenames in the current directory by the shell, but the -C will make tar change directory internally so the files won't be found. I've never used -C in anger before so I hadn't thought about that. The basic principle is sound, you just need to work around that.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
There was an error copying the file into smb:// PcName/Folder/Folder morbid_bean Linux - Networking 3 01-19-2017 04:44 AM
Copying Latest Files to Another Folder nformosa Programming 9 04-23-2009 06:40 AM
copying folder and changing extension of files in it? stratotak Linux - Newbie 18 03-10-2009 01:16 AM
automatically inherit parent folder permissions when copying files teixeira Linux - Newbie 3 07-08-2008 12:21 PM
Need a simple shell script please overwritting files. stefaandk Programming 9 10-11-2006 07:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:58 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
Open Source Consulting | Domain Registration