LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-17-2011, 03:24 PM   #1
chongman99
LQ Newbie
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Morphix 0.4 (Debian based)
Posts: 21

Rep: Reputation: 0
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
 
Old 10-17-2011, 04:33 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,451
Blog Entries: 54

Rep: Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894
Option 3, no need to quote files.
 
Old 10-17-2011, 06:29 PM   #3
chongman99
LQ Newbie
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Morphix 0.4 (Debian based)
Posts: 21

Original Poster
Rep: Reputation: 0
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!
 
Old 10-18-2011, 10:49 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,491

Rep: Reputation: 621Reputation: 621Reputation: 621Reputation: 621Reputation: 621Reputation: 621
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'.
 
  


Reply

Tags
find, rsync


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
spaces in filenames dotancohen Programming 12 02-17-2006 02:42 PM
filenames with spaces antony.booth Programming 5 11-01-2005 04:49 AM
ls and filenames with spaces rose_bud4201 Programming 10 07-01-2005 08:28 AM
BASH scripting problem, spaces in filenames / using basename textures Programming 24 11-16-2003 01:41 AM
spaces in filenames ebone Linux - General 2 11-12-2001 11:56 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration