1

I have the following filestructure in my src directory:

en/
en/a/
en/a/file1 -> ../../en/mp3/file1-longer-name-a
en/a/file2 -> ../../en/mp3/file2-longer-name-a
en/mp3/file1-longer-name-a
en/mp3/file1-longer-name-b
en/mp3/file2-longer-name-a
en/mp3/file3-longer-name-a

I am interested to copy all the files under en/a/ to the destination, preserving symlinks, and also include the referent files (which BTW are all within en/) but not other files under en/mp3/ if they are not referred by any symlinks I am transferring.

I'm using the following command, that does the obvious part of the job:

rsync -avRz "${SRC}./en/a" "${DST}"

this transfers the following files:

en/
en/a/
en/a/file1 -> ../../en/mp3/file1-longer-name-a
en/a/file2 -> ../../en/mp3/file2-longer-name-a

and I hope you'll help me to tweak the rsync args so that the following files will be transferred too:

en/mp3/file1-longer-name-a
en/mp3/file2-longer-name-a

is there a way to achieve this without needing to write an algorythm to loop over the softlinks under en/a/ and transfer the files they point to one-by-one?

2
  • This doesn't exactly answer your question, but you might have a look at rsync's --copy-links or -L flag. Instead of copying the symlinks it resolves them and copies the files. But that's not a good idea if you've got many links to one file.
    – mreithub
    May 6, 2013 at 8:53
  • I already tried that, but I need the symlinks to stay symlinks in the en/a/ directory
    – Gavriel
    May 6, 2013 at 9:03

1 Answer 1

0

You could use find in combination with rsync's --files-from parameter:

find "${SRC}./en/a" -type l -exec readlink {} ';'|sort|uniq|rsync -avRz --files-from=- "${SRC}" "${DST}"
  • find lists all symlinks in the en/ folder and executes readlink on each of them.
  • then we sort the list and filter out duplicates (with sort and uniq)
  • and rsync gets the --files-from param set to - to read the files it should sync from stdin
2
  • OK, it worked, the only thing I had to change was: rsync -avRz --files-from=- "${SRC}" "${DST}" (i.e: removed "./en/a", because the files that find gave me already had that)
    – Gavriel
    May 6, 2013 at 10:25
  • Fixed the answer.
    – mreithub
    May 6, 2013 at 10:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .