On 2024-03-05 06:16, Pádraig Brady wrote: > I think I'll remove the as yet unreleased mv --swap from coreutils, > given that > util-linux is as widely available as coreutils on GNU/Linux platforms. Although removing that "mv --swap" implementation was a win, I don't think we can simply delegate this to util-linux's exch command. Exchanging files via a renameat-like call is not limited to the Linux kernel; it's also possible on macOS via renameatx_np with RENAME_SWAP, and there have been noises about adding similar things to other operating systems. I just now added support for macOS renameatx_np to Gnulib, so coreutils does not need to worry about the macOS details; it can simply use renameatu with the Linux flags. See: https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=af32ee824ee18255839f9812b8ed61aa5257a82b Even with Linux it's dicey. People may have older util-linux installed and so lack the 'exch' utility; this is true for both Fedora 39 and Ubuntu 23.10, the current releases. Ubuntu is also odd in that it doesn't install all the util-linux utilities as part of the util-linux package, so it's not clear what they will do with 'exch'. So I propose that we implement the idea in coreutils in a better way, that interacts more nicely with -t, -T, etc. Also, I suggest using the Linuxish name "--exchange" instead of the macOSish name "--swap", and (for now at least) not giving the option a single-letter equivalent as I expect it to be useful from scripts, not interactively. After looking at various ways to do it I came up with the attached proposed patch. This should work on both GNU/Linux and macOS, if your OS is recent enough and the file system supports atomic exchange.