Syncing files with rsync by file names only, ignore directories

rsync

I'm trying to sync files from System A to System B. However, the files are re-organized in another directory structure, which makes usage of rsync difficult.

Is there any way to tell rsync to ignore directories and operate on file names only? The file names are unique – the directories aren't. The directory structure isn't fixed, so I can't simply replace them. I already thought about writing a script which strips the directory information, but I'm not sure if that brings up other problems.

In fact, yes, I wish to flatten the directory structure. Given the answers, rsync is probably not what I wish to use.

I'm working with videos, third parties create a directory structure (and they should be allowed to change the directory structure whenever appropriate). Those videos need to be syncronized to a master file system. File names are agreed not to be changed. So something like a diff between "find . | rip-out-path" on both systems and a diff might do the trick; but I was wondering if rsync had some magic flag to ignore directories at all when recursing – similar to the -p parameter in patch.

Best Answer

Probably the simplest way to solve moving all files from on directory tree to a single directly would be using find with the -type and -exec options. The -type option limits the output to a specific type of directory entry (f for file, d for directory, etc.). The -exec option passes the name found (as {}) to a command line with options.

A couple examples follow:

find /directory/top/ -type f -exec rsync {} desthost:/destdir 

find /directory/top/ -type f -exec scp {} desthost:/destdir 
Related Topic