Skip to content

Instantly share code, notes, and snippets.

@yuwash
Created August 6, 2023 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuwash/3a94f569160ac3e9a6181e65f7d7d45f to your computer and use it in GitHub Desktop.
Save yuwash/3a94f569160ac3e9a6181e65f7d7d45f to your computer and use it in GitHub Desktop.
Archive Move
# Armv "Archive Move"
# A command to write a "moved.txt" file in the source directory with a
# list of files moved and the destination.
# The command also moves all the files to the destination.
# Usage: armv source/path dest/path
FROM_PATH="$1"
TO_PATH="$2"
MOVED_FILE_HEADER="TO: $(realpath "$TO_PATH")"
MOVED_FILE_PATH="${FROM_PATH}/moved.txt"
TEMP_MOVED_FILE_PATH="/tmp/moved-$(head -c 8 <(echo -n "FROM_PATH" "TO_PATH" | sha1sum)).txt"
echo $MOVED_FILE_HEADER > "$TEMP_MOVED_FILE_PATH"
ls "$FROM_PATH" >> "$TEMP_MOVED_FILE_PATH"
rsync -arv --progress --ignore-existing --remove-source-files "$FROM_PATH/" "$TO_PATH"
# This part is NOT safe against concurrent changes to FROM_PATH!
# The list in moved.txt might be outdated in that case.
mv -nT "$TEMP_MOVED_FILE_PATH" "$MOVED_FILE_PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment