LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

exch

utility to swap two file paths

TLDR

Swap filepaths of two files
$ exch [path/to/file1] [path/to/file2]
copy

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 swap
file2
Second file to swap

INSTALL

sudo apt install util-linux-extra
copy
sudo apk add util-linux-misc
copy

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.

SEE ALSO

mv(1), cp(1), rename(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid