LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Problem with rsync and filenames with spaces, backquotes (http://www.linuxquestions.org/questions/linux-general-1/problem-with-rsync-and-filenames-with-spaces-backquotes-908645/)

chongman99 10-17-2011 04:24 PM

Problem with rsync and filenames with spaces, backquotes
 
THE QUESTION

I am trying to rsync all files in the last X (10) days. This command is how to do it:

Code:

rsync `find . -name "*" -mtime -10` ~/destination
And it works perfectly, except that if I have a space in a file name, it treats each space-delimited fragment as a separate file.

I know that if I have filenames with spaces, I have to backquote the spaces and possibly quote the filename. I can do this file by file, but don't know how to process the find command to add them in.

Anyone have a tip of how to do this?

I've got some ideas, but haven't implemented any correctly and thought it would be time for help.
  1. pipe the find results to sed to add quote each line
  2. pipe to sed and add replace " " with "\ "
  3. output to file and use the rsync option to specify a file list, "--files-from=" (do I need to quote each line of find)
  4. use find with -print0 and use xargs

unSpawn 10-17-2011 05:33 PM

Option 3, no need to quote files.

chongman99 10-17-2011 07:29 PM

Ok, I got it to work with option 3.

I made a dumb mistake using the "--files-from=" option. I forgot to specify the source directory.

This is correct:
Code:

find -mtime -10 -print > filelist
rsync -R --files-from=filelist . ~/todir

This is incorrect:
Code:

find -mtime -10 -print > filelist
rsync -R --files-from=filelist ~/todir

It is incorrect because I left out the "." as the SRC directory.

Thanks a bunch!

rknichols 10-18-2011 11:49 AM

You still would have a problem with file names that contain an embedded newline character. To be completely safe, you should use "-print0" in the 'find' command, and "--from0" (or just "-0") in 'rsync'.


All times are GMT -5. The time now is 11:14 AM.