20

Using rsync, how can I rename files when copying with the --files-from argument? I have about 190,000 files, each of which need to be renamed when copying from source to destination. I plan to have the list of files in a text file to pass to the --files-from argument.

Mark Richman
  • 28,948
  • 25
  • 99
  • 159

2 Answers2

14

Not entirely true... you CAN rename files enroute with rsync, but only if you rsync one file at a time, and set the --no-R --no-implied-dirs options, then explicitly set the destination name in the destination path.

But at that point, you may just want to use some other tool.

This, for example, would work:

rsync --no-R --no-implied-dirs
1.2.3.4::module/$FILENAME
/$PATH/$TOFILE/$NEWFILENAME
George Udosen
  • 906
  • 1
  • 13
  • 28
user129070
  • 141
  • 1
  • 2
  • 4
    Actually, rsync is useful for a single file in some circumstances. If the file is large, and has either only had minor changes, or has only been appended to, it's a good fit. – Royce Williams Jun 08 '15 at 14:28
  • 2
    According to man page, `--no-implied-dirs` only affects how `--relative` works. And `--relative` is the same as `-R`. But you use `--no-R`, which makes me wonders what effect `--no-implied-dirs` is supposed to have in that case? – Mecki Oct 12 '17 at 19:12
11

There is no way to arbitrarily rename files with rsync. All rsync can do is move files to a different directory.

You must use a second tool either on the sending or receiving side to rename the files.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820