LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-15-2014, 01:24 PM   #1
AnalBeard
Member
 
Registered: Aug 2010
Distribution: Ubuntu 13.04 Server
Posts: 31

Rep: Reputation: 0
Duplicating a directory tree with rsync


I'm currently duplicating a directory tree with hard links with this command:

Code:
cp -aluv /path/to/sourcedir/* /path/to/destdir/
Now for the most part, all files are in subdirs under the sourcedir, but there are a few pesky files in the root of sourcedir - I'd like to exclude duplicating those. These files are all of the same type (pdf) so I could exclude .pdfs, but there will be some deeper in the directory tree which needs to be copied. Is there any way I could achieve this? I know you can provide rsync with an exclude list, but I can't see any way of achieving this with cp.
 
Old 07-15-2014, 01:31 PM   #2
AnalBeard
Member
 
Registered: Aug 2010
Distribution: Ubuntu 13.04 Server
Posts: 31

Original Poster
Rep: Reputation: 0
Ok, I feel a bit daft now as I may well have sussed it:

Code:
find /path/to/sourcedir/ -mindepth 1 -exec cp -aluv {} /path/to/destdir/ \;
how does that look?

edit: ok, just tried that out, it doesn't work (and should have been obvious). Obviously it just copies all files it finds to the the root of destdir - doh. Just noticed the --parents flag, but that creates the entire directory path in destdir (so /path/to/destdir/path/to/sourcedir/)

further edit: right, so to wrap this up, I realised this was partially due to my stupidity. By changing to the sourcedir and then specifying the correct mindepth (2), I ended up with a working solution:

Code:
cd /path/to/sourcedir && find . -mindepth 2 -exec cp -aluv --parents {} /path/to/destdir/ \;

Last edited by AnalBeard; 07-15-2014 at 02:57 PM.
 
  


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
using rsync to keep local copy of stable tree up to date chexmix Slackware 3 05-15-2011 02:59 PM
duplicating a live server with rsync? dragos19 Linux - General 1 05-20-2008 01:59 PM
SAMBA and duplicating directory lists in XP salmageo Linux - Server 2 05-16-2008 02:26 PM
Copying a single file into each directory of a directory tree mlapl1 Linux - Newbie 2 06-27-2007 10:18 PM
permissions for directory tree adamwenner Linux - Security 3 10-23-2004 07:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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