Skip to content

Instantly share code, notes, and snippets.

@dmgolembiowski
Created May 5, 2025 21:40
Show Gist options
  • Save dmgolembiowski/041aa63eb518c6409f652a20d364f16c to your computer and use it in GitHub Desktop.
Save dmgolembiowski/041aa63eb518c6409f652a20d364f16c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Path: /usr/bin/swap
function swap() {
if [ ! -f "$1" ] || [ ! -f "$2" ]; then return 1; fi
TMPFILE=/dev/shm/tmp.$$
dd if="$1" of=$TMPFILE status=none bs=512K && \
dd if="$2" of="$1" status=none bs=512K && \
dd if=$TMPFILE of="$2" status=none bs=512K && \
( \
if [ $? -ne 1 ]; then true; else unlink $TMPFILE && unset $TMPFILE; return 1; fi; \
) && \
sync && \
unlink $TMPFILE
unset TMPFILE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment