exch
utility to swap two file paths
TLDR
Swap filepaths of two files
$ exch [path/to/file1] [path/to/file2]
SYNOPSIS
exch file1 file2
DESCRIPTION
exch atomically exchanges two paths. After the operation, file1 refers to what was at file2's path and vice versa. It is a thin wrapper around the RENAME_EXCHANGE flag of the renameat2(2) system call.Part of the util-linux package. Useful for quickly swapping configuration files, symlinks, or backups without an intermediate temporary name.
PARAMETERS
file1
First file to swapfile2
Second file to swap
INSTALL
sudo apt install util-linux-extra
sudo apk add util-linux-misc
CAVEATS
Both files must exist. The exchange is atomic (no window where either name is missing), unlike a three-step mv dance. Requires renameat2(2) with RENAME_EXCHANGE, so it is Linux-only and both paths must reside on the same filesystem. Added in util-linux 2.41.