Skip to content

Instantly share code, notes, and snippets.

@mekb-turtle
Last active April 28, 2023 08:55
Show Gist options
  • Save mekb-turtle/4635c23aa16ed3bcd019b987fcd9c287 to your computer and use it in GitHub Desktop.
Save mekb-turtle/4635c23aa16ed3bcd019b987fcd9c287 to your computer and use it in GitHub Desktop.
bash script to swap two files around
#!/usr/bin/bash
if [[ "$#" != "2" ]]; then echo "Usage: swapfile <file1> <file2>"; exit 1; fi
if [[ ! -e "$1" ]]; then echo "File not found: $1"; exit 1; fi
if [[ ! -e "$2" ]]; then echo "File not found: $2"; exit 1; fi
IDTEMP="$(uuidgen|tr -d '-')"
mv -v "$1" "$1$IDTEMP" && mv -v "$2" "$1" && mv -v "$1$IDTEMP" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment