Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 05-31-2010, 09:56 AM   #1
LQ Newbie
Registered: May 2003
Posts: 18

Rep: Reputation: 0
rsync and find - how do I get the paths right?

I have a problem using rsync and find together.

I want to use find to create a file list for rsync to use with the --files-from option. I need to do this because the files can be moved from the target directory at a later date, but may remain in the source directory. I can't get find to generate the right paths for rsync.

Here's a fragment of my bash script:

RSYNC="/usr/bin/rsync --archive --size-only --verbose"
find ${SOURCE} -mtime -7 > /tmp/rsync_files
${RSYNC} --files-from=/tmp/rsync_files / ${TARGET}
This recreates the full path under TARGET.

If I do this:
${RSYNC} --files-from=/tmp/rysnc_files ${SOURCE} ${TARGET}
This can't find the source files.

I need find to return the partial paths starting at the SOURCE directory, but can't see an easy way to do this.
Old 05-31-2010, 10:15 AM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960
What does the path in your ${SOURCE} variable look like? Find seems to build it's output based on the directory string used. If you use an absolute path the output will have an absolute path, but if you use a relative one, it will have a relative path.

Another thing to look at, assuming you're using the GNU version of find, is the -printf option. It will allow you to format the output in various ways, so you might be able to build an appropriate output string with it.

Finally, you might want to simply use sed on your output file to change the paths to the format you want.
Old 05-31-2010, 10:23 AM   #3
LQ Newbie
Registered: May 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks for the suggestions.

I actually just did it by cding to the source directory, then using "find .".

But I have another problem. Even though I now pass the file list to rsync, it tries to sync all the files in the source directory.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
find: paths must precede expression lead2gold Linux - General 11 02-27-2014 07:06 AM
[SOLVED] rsync two directories, slashes at ends of paths or not rjo98 Linux - Newbie 3 10-23-2009 03:25 PM
Problem with find: paths must precede expression troelskn Programming 11 07-29-2009 02:48 AM
Algorithm to find paths xeon123 Programming 5 04-24-2007 02:18 AM
Wine can't find paths in Mandriva 2005 LE kalahari875 Mandriva 3 06-28-2005 07:22 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:18 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration