Urgent.News

What's breaking now, across thousands of outlets.

Tech

What `rsync -avz --delete` Actually Does

A lot of people paste rsync -avz --delete into a deploy script and move on without ever unpacking what each letter means. It works, so there's rarely a reason to stop and ask. But understanding what each flag actually instructs the command to do makes it much easier to reason about exactly how far --delete reaches, and why the other flags are there in the first place. This post breaks down the…

The rsync command is a powerful tool for synchronizing files between locations. When used with the flags -avz --delete, it performs a recursive copy of files while preserving metadata like permissions and timestamps, compresses the data being transferred to save bandwidth, and optionally removes files from the destination that no longer exist in the source. This combination of flags is commonly used to mirror the contents of one directory to another.

Breaking down the flags:

- -a: Archive mode, which recursively copies files while preserving permissions, timestamps, symbolic links, and ownership. This is equivalent to several other flags combined: -r (recursive), -l (copy symlinks as symlinks), -p (preserve permissions), -t (preserve modification times), -g (preserve group ownership), -o (preserve owner), and -D (preserve device files and special files). A notable aspect of -a is the preservation of timestamps, which is crucial for rsync's change-detection mechanism to work correctly.

- -v: Verbose mode, which prints the name of every file transferred, providing a detailed output of the synchronization process.

- -z: Compresses the data being transferred, reducing the amount of bandwidth used during the synchronization process.

- --delete: This flag is what allows rsync to mirror the destination directory to the source directory. It removes files from the destination that no longer exist in the source, ensuring that both directories match exactly. However, its scope is limited to the specific source and destination directories provided. If the destination path is not narrowly scoped, --delete can inadvertently remove files from sibling directories outside the intended scope.

A practical example of using rsync with these flags for a theme deployment is provided. The command is carefully scoped to the specific theme directory, ensuring that --delete only removes files from the theme's directory and not from other themes or directories on the server. This careful scoping is essential to avoid unintended file deletions.

The -e flag is used to specify the connection method, in this case, SSH with a key file and a specific port. This is important for secure and unattended deployments. The trailing slash in the source path ensures that the contents of the theme directory are copied directly into the destination, rather than being nested one level deeper.

In summary, the rsync -avz --delete flags together create a powerful and safe tool for synchronizing directories. The key to using --delete safely is to carefully scope the destination path to ensure that only the intended files are removed.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at dev.to →

More in Tech

Property Domain Offboarding — Delete Records Without Whole-Zone Risk

Short answer: retire only the records owned by the departing property, never the whole DNS zone, unless an ownership check proves that the zone itself has no other consumers.

  • Delete DNS records property by property, not entire zone
  • Lower TTL before deletion, wait for old TTL window
  • Maintain rollback data until resolver confirms changes

More from Friday 18 September →