Skip to content

Instantly share code, notes, and snippets.

@psenger
Created February 15, 2024 23:59
Show Gist options
  • Save psenger/99c08613c48fac133fe0dcbed07b6432 to your computer and use it in GitHub Desktop.
Save psenger/99c08613c48fac133fe0dcbed07b6432 to your computer and use it in GitHub Desktop.
[Exact Copy] #MacOS #Unix

Exact Copy

Copy everything from one directory to another directory on a different volume in Unix, while retaining permissions, ownership, structure, as well as all creation and modification dates (timestamps)

When Destination is Fresh

rsync -avHAX --numeric-ids /source/directory/ /destination/directory/

Caution - removes destination files

rsync -avHAX --numeric-ids --delete /source/directory/ /destination/directory/

Options Break Down:

  • -a, --archive: This option enables archive mode, which is equivalent to -rlptgoD. It ensures that symbolic links, devices, attributes, permissions, ownerships, etc., are preserved in the copy. Additionally, it recurses into directories.
  • -v, --verbose: This option provides verbose output, showing the details of the transfer.
  • -H: This option preserves hard links, ensuring that hard-linked files in the source directory are also hard-linked in the destination directory.
  • -A: This option preserves Access Control Lists (ACLs) to maintain the exact access control information.
  • -X: This option preserves extended attributes, which are used to store extra data and settings on files and directories.
  • --numeric-ids: This ensures that numeric user and group IDs are preserved, which is particularly useful when copying files to a system where the user and group names might not exist.
  • --delete: This option deletes extraneous files from the destination directory to ensure that the destination is an exact copy of the source. Use this option with caution, especially if the destination directory contains data that might not exist in the source directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment