Update: Atomic cross-rename of two paths (mv --exchange, exch)
[ date: 2025-01-11 || tags: mv,coreutils,util-linux ]I did not notice that the cross rename already existed when I was writing about it but it’s been there since coreutils v9.5 released in Mar 2024.
$ mv --exchange file1 file2
And it also landed in util-linux v2.40
at about the same time as utility exch
(added in commit cd094a05880c):
$ exch file1 file2
The two projects have an overlap in what they provide so the journey of mv
--exchange
took a few turns:
From coreutils git:
- 2024-02-29 6cd2d5e5335b
mv: add --swap (-x) option to atomically swap 2 paths
- 2024-03-05 9d8890d87231
mv: revert add --swap (-x) option
- 2024-03-20 5d3fd24f4286
mv: new option --exchange
Good that the feature is provided in standard tools but unfortunately none of
them comes with a decent description of the capabilities and limitations. All
types of files, directories (including subvolumes) could be exchanged but only
on the same filesystem, otherwise it returns the error EXDEV
Invalid cross-device link.