-
-
Save yuwash/3a94f569160ac3e9a6181e65f7d7d45f to your computer and use it in GitHub Desktop.
Archive Move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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