Skip to content

Instantly share code, notes, and snippets.

@ErykDarnowski
Created April 16, 2024 17:17
Show Gist options
  • Save ErykDarnowski/3cb5db1eb465ef1fd05fb4d165d454dc to your computer and use it in GitHub Desktop.
Save ErykDarnowski/3cb5db1eb465ef1fd05fb4d165d454dc to your computer and use it in GitHub Desktop.
Copy missing files from source to destination dir on Linux
#!/bin/bash
# THIS ONLY CHECK THE DIFF IN AMOUNT OF FILES, NOT ACTUAL CONTENT!!!
# Make sure the SRC path has more files than the DST.
SRC_PATH="/d/Games/SteamLibrary/steamapps/common/assettocorsa/content/cars"
DST_PATH="//192.168.1.5/home/Backupy/AC Content Manager/content/cars"
DIFF_RESULT=$(diff --brief "$DST_PATH" "$SRC_PATH" \
| sed --quiet "s~^Only in \($SRC_PATH\): \(.*\)~'\1\/\2'~p")
if [ -n "$DIFF_RESULT" ]; then
echo -e "\n"
echo "$DIFF_RESULT" \
| xargs cp --recursive --verbose --target-directory="$DST_PATH"
echo -e "\n---\n\n@ DONE";
exit 0;
else
echo -e "\n@ ERR: Nothing to copy!!!";
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment