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 |
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. |
|
 |
06-15-2011, 05:38 PM
|
#1
|
|
Member
Registered: Apr 2006
Location: North Vancouver, B.C., Canada
Distribution: Fedora 14
Posts: 38
Rep:
|
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
|
|
|
|
06-16-2011, 05:01 AM
|
#2
|
|
Senior Member
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,314
|
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.
|
|
|
|
06-16-2011, 05:15 AM
|
#3
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,897
|
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
|
|
|
|
06-16-2011, 06:05 AM
|
#4
|
|
Member
Registered: Feb 2009
Posts: 275
Rep:
|
If you really want to use a text file awk is probably the answer.
|
|
|
|
06-20-2011, 01:02 PM
|
#5
|
|
Member
Registered: Apr 2006
Location: North Vancouver, B.C., Canada
Distribution: Fedora 14
Posts: 38
Original Poster
Rep:
|
. . . 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
|
|
|
|
06-20-2011, 02:34 PM
|
#6
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,897
|
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.
|
|
|
|
| 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 02:37 AM.
|
|
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
|
|