LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2011, 05:38 PM   #1
Ryanjon7
Member
 
Registered: Apr 2006
Location: North Vancouver, B.C., Canada
Distribution: Fedora 14
Posts: 38

Rep: Reputation: 15
using rsync to copy only certain folders within a directory structure


Hello,

I am trying to create a simple bash script to rsync some folders within a directory stucture. I am using wild cards, in the rsync source directory structure, but my command always fails. I believe it is the way I am using wild cards within my for loop. Here is my command ;

Code:
for seq in `cat test.txt` ; do rsync -nvP /folder/folder/folder/folder/folder/**/$seq /folder/folder/folder/ ; done
This always fails, where if I do a ls to the destination, to test the path, it always works. Any help and suggestions would be appreciated

Thanks,

ryjguy7
 
Old 06-16-2011, 05:01 AM   #2
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Do you expect ** to behave different from a plain *?

To get a list of source directories you could also build them beforehand by a find command. You want to have something like:
Code:
$ find /folder/folder/folder -path "*suffix1" -o -path "*suffix2"
to get a list of directories.
 
Old 06-16-2011, 05:15 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You might also consider the --exclude and --include options of rsync (or --exclude-from and --include-from if you keep the pattern in a file). If you want to sync only some of the existing directories in a path, you can do something like:
Code:
rsync -av --exclude=* --include=dir1/ --include=dir2/ --include=dir3/ source destination
otherwise if you want to list the directories to exclude, use multiple --exclude options:
Code:
rsync -av --exclude=dir1/ --exclude=dir2/ --exclude=dir3/ source destination
 
Old 06-16-2011, 06:05 AM   #4
impert
Member
 
Registered: Feb 2009
Posts: 282

Rep: Reputation: 54
If you really want to use a text file awk is probably the answer.
 
Old 06-20-2011, 01:02 PM   #5
Ryanjon7
Member
 
Registered: Apr 2006
Location: North Vancouver, B.C., Canada
Distribution: Fedora 14
Posts: 38

Original Poster
Rep: Reputation: 15
. . . Thanks for your responses and help guys.

Is there a way to tell the find command to search only for directories, and if so to create the directory structure it finds.

Thanks,

ryjguy7
 
Old 06-20-2011, 02:34 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The find command has a -type option. Using type -d you can search only directories. If you want to re-create a directory structure, you can use rsync, e.g.
Code:
rsync -av --include '*/' --exclude '*' source destination
Note the --include option with the slash after the wildcard: it includes only directories, whereas the --exclude option excludes all the rest, that is the files. Hope this helps.
 
  


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
Copy Directory Structure Only ronin1 Linux - Newbie 10 06-08-2013 06:23 AM
make rsync ignore directory structure? illumilore Linux - General 1 04-20-2011 12:46 AM
[SOLVED] rsync with changing directory structure dormant Linux - Software 6 08-28-2010 03:32 PM
RSYNC Directory Structure? carlosinfl Linux - General 2 09-18-2007 01:58 PM
Copy directory structure? tpe Programming 2 06-02-2005 04:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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