Make rsync move (not copy) files on local file system

filesmvperformancersync

Can I make rsync to move large amount of files instead of copying them when on local filesystem? I would like it to behave like improved mv command. I know about --remove-source-files option but manual does not say anything whether it actually moves files (desired) or just copies and then delete (not desired).

Edit
What I want to achieve is that rsync (improved mv) moved files into directories merging existing directories — same as rsync -r but moving not copying e.g.

$ tree d1 d2
d1
├── b
├── c
├── d
├── deep_house
│   └── dh1
└── sound
    └── sss
d2
├── a
└── deep_house
    └── dddx

3 directories, 7 files
$ rsync -r d1/ d2
$ tree d2
d2
├── a
├── b
├── c
├── d
├── deep_house
│   ├── dddx
│   └── dh1
└── sound
    └── sss

Best Answer

Rsync copies files. That's what it does. Even if you tell it to remove source files, it still copies them first, it never moves them, even when the destination happens to be on the same filesystem.

The mv utility from GNU coreutils has an option -u to move files only if the destination is older than the source or doesn't exist yet. This is similar to rsync's -u.

If you want to move a directory tree into an existing one, you can use a recursive traversal that calls mv on every file. If you don't want to overwrite existing files:

cd d1
find . -depth -exec sh -c 'test -e "../d2/$0" || mv "$0" "../d2/$0"' {} \;

If you do want to overwrite existing files, you'll need to distinguish between existing directories and other files, and to decide what to do when the source has a regular file where the destination has a directory.

Related Question