Skip to content

Instantly share code, notes, and snippets.

@brunopk
Last active February 21, 2024 04:09
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 brunopk/37c9703b9bc82061d32303d99d29d9fb to your computer and use it in GitHub Desktop.
Save brunopk/37c9703b9bc82061d32303d99d29d9fb to your computer and use it in GitHub Desktop.
Useful commands for Linux and macOS

rsync

For all the examples below, asume there exist src (source) and dest (destination) folders.

Example 1

rsync --recursive --delete src dest

--delete: to delete files/folders which exist in dest/ but don't exist in src/

Example 2

rsync --recursive --delete src/ dest

Same as 1 but without creating dest/src/ folder (just copying src content to dest):

Example 3

$ rsync -aP --delete src/ dest

-a: archive mode, which is necessary for rsync to identify modified files requiring copying.

-P: show progress.

Example 4

Over SSH and using custom keys ($HOME/.ssh/somekey):

rsync -Pav -e "ssh -i $HOME/.ssh/somekey" username@hostname:/from/dir/ /to/dir/

-P: show progress.

-v: verbosity.

Example 5

rsync --recursive \
  --progress \
  --archive \
  --exclude-from=.gitignore \
  --exclude=.git \
  --exclude=.gitignore \
   folder user@ipaddress:~/dest/

Similar to previous examples to copy over SSH.

--exclude-from: receives a file path with a format similar to CVS ignore files, such as the .gitignore file in Git, to indicate which files and directories should be excluded.

--exclude: indicates a folder or file to exclude.

More information

date

Get an UTC date in ISO format :

date -u +"%Y-%m-%dT%H:%M:%SZ"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment