When only rsync will do .. or maybe not

Andrey Repin anrdaemon@yandex.ru
Sat Oct 22 14:39:19 GMT 2022


Greetings, Fergus Daly!

> Requirement: to move some selected files and folders under /folder1/ to /folder2/, preserving full pathnames.

Full pathname would include the /folder1 making the requirement impossible
from the start.
If, on the other hand, you want to preserve directory structure, then a simple

    cd /f1; find . -xdev -type d -exec mkdir -p "/f2/{}" ';' -o -type f -exec mv '{}' "/f2/{}" ';'

will do.

> One solution would be (i) to copy the required content to /folder2/ and
> then (ii) delete the identical content under /folder1/;
> but this is expensive (one might not even have the disk space to do it) and
> it seems seriously unsatisfactory and not without risk
> to have to copy folders and files (possibly huge) when all one wants to do is to change the {pathname} to them.

`cp --reflink=always` will take care of duplicated content.
Do note that paths must be relative. cp has an issue detecting "same volume"
and failing or falling back to simple copy.

> Question 1
> Would the command (or something like it, again with care over syntax and $PWD)
> $ rsync -axuv --progress {pathto}/folder1/{content} {pathto}/folder2/   
> do the trick? Or is the very existence of the switch
> $ rsync -axuv --remove-source-files --progress {pathto}/folder1/{content} {pathto}/folder2/
> indicative that here too the "move" is achieved through a two-stage "copy-then-delete" operation?

> Question 2
> If rsync can provide a genuine "move" capability then is installing the
> rsync package adequate to the purpose;
> or would librsync-devel and/or librsync2 packages need to be installed also?

No, not the purpose of rsync.

> Question 3
> If not rsync, is there any operation for which "move" can be achieved
> without involving "copy-then-delete"? 

Yep.
See above.


-- 
With best regards,
Andrey Repin
Saturday, October 22, 2022 11:56:05

Sorry for my terrible english...



More information about the Cygwin mailing list