Skip to content

Instantly share code, notes, and snippets.

@turboBasic
Created January 26, 2021 01:46
Show Gist options
  • Save turboBasic/b75ab85f01c33f82ed975cde8b2e17e2 to your computer and use it in GitHub Desktop.
Save turboBasic/b75ab85f01c33f82ed975cde8b2e17e2 to your computer and use it in GitHub Desktop.
Copy files to other user's home #bash
#!/usr/bin/env bash
DEST_USER=${DEST_USER:-user}
DEST_DIR=${DEST_DIR:-/home/$DEST_USER}
files="$(
sudo --login --non-interactive --user $DEST_USER -- \
bash -c "find -maxdepth 1 -type f \\(
-name .profile -o -name .zprofile -o -name .bash\\* -o -name .zsh\\*
\\)"
)"
printf '%s\n' "$files" | \
sudo --login --non-interactive --user $DEST_USER -- \
tar -czvf "backup_shell-files.tgz" \
--directory "$DEST_DIR" \
--backup=numbered \
--verbatim-files-from \
--files-from=-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment