LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-03-2015, 11:05 AM   #1
thm
LQ Newbie
 
Registered: Sep 2015
Posts: 2

Rep: Reputation: Disabled
How copy older backup files into new folder witout losing new additional files


I have a backup folder with differen subfolder and a lot of files and an newer folder with subfolder and files. The new folder has some additonal files, which don't want lose by copying the old folder back. Some files in the old and the new folder have the same name but they have different sizes.
I want to copy the old file variant into the new folder, but not lose the additonal new files. With which command is this possible?
 
Old 09-03-2015, 01:14 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
So you want to copy the old directory to the newer one? If you use cp -r it will recurse through subdirectories and absent the -n (noclobber) option, then those old file copies will overwrite the newer copies that it sounds like you wanted to replace. Either case, non-overlapping files, such as pre-existing ones in the destination directory will be left alone.

Am I understanding correctly what you want to do?
 
Old 09-04-2015, 01:13 AM   #3
thm
LQ Newbie
 
Registered: Sep 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks a lot for your answer.
Yes, I want to copy the oder directory to the newer one. But I want replace only the overlapping files, the additional, non-overlapping files in the newer directory shouldn't be touched.
For this case the command line cp -r -n would work?
 
Old 09-04-2015, 04:32 PM   #4
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 529

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
No, the command to copy all and overwrite existing files in the destination directory is just cp -r with the appropriate source and destination specifiers.

By the way, if you need to copy the contents of a directory, not the directory itself, you will need to correctly specify the source, or it may copy the source directory into the destination directory (creating the copies as a subdirectory). One method to avoid this mistake is to cd into the backup directory and then cp the contents, for example:
Code:
cd /my_backups/backup_directory
cp -r * /home/thm/destination_directory
Alternatively you could cp the directory and append /* when specifying the source:
Code:
cp -r /my_backups/backup_directory/* /home/thm/destination_directory
 
  


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
[SOLVED] Using terminal command -Find files in a folder and copy them to a different folder j-jock Linux - General 4 11-28-2011 02:20 AM
Copy files and folder except some files and folders chintan_gaurav8 Linux - General 1 06-08-2010 01:36 AM
backup files to DVD older than a certain date terp4life2001 Linux - Software 1 10-17-2009 12:25 AM
Automated script to DELETE files older than 2 days in a Particular folder siddhartha_ece2004 Linux - Newbie 14 07-11-2008 05:46 AM
bash: delete files older than 7 days in a folder and subfoldes lupomanaro Programming 1 05-07-2008 10:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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