Dino Geek, try to help you

What is --delete option in RSYNC?


`—delete` is an important option in rsync, a powerful and flexible command tool in Linux utility, known for file synchronization, copying, and data migration.

When we use rsync command without the `—delete` option to synchronize files from the source to the destination directory, the new files from the source directory will be copied, but deleted files will not be removed from the destination directory. On the other hand, when the `—delete` option is used with the rsync command, it ensures that if a file or directory is deleted from the source directory, it will also be deleted in the destination directory. This behavior mirrors the source and destination directory files exactly.

Here’s an example:

1. Create a source directory called `src` with 3 files:
```
mkdir src
touch src/file1 src/file2 src/file3
```
1. Create a destination directory `dest` and sync with `src`
```
mkdir dest
rsync -av src/ dest/
```
1. At this point `dest` directory will have `file1`, `file2`, and `file3`. Now, if you delete `file3` from the `src` directory:
```
rm src/file3
```
1. And then do a simple rsync again (without `—delete`), `file3` will still exist in the `dest` directory.
2. If you now do rsync with `—delete`:
```
rsync -av —delete src/ dest/
```
1. This ensures that `file3` gets deleted from `dest` directory too.

Although `—delete` helps to maintain the exact copy of the source directory to the destination directory, it should be used with caution. You might lose data if you accidentally delete anything in the source directory, as it will also be deleted in the destination directory in the next sync.

There are also more variations for the `—delete` option like `—delete-before`, `—delete-during`, `—delete-delay`, and `—delete-after` which controls the timing of when files are deleted during sync operation.

The information used in constructing this was taken from the manual pages of rsync (`man rsync` in Linux terminal) and explained further with examples inspired by Geek’s Diary and Tecmint articles on how to use rsync effectively.

References:

1. “Rsync (Remote Sync): 10 Practical Examples of Rsync Command in Linux”.Tecmint. https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/
2. Glantz, R. “Linux rsync command help and examples”. Computer Hope. https://www.computerhope.com/unix/rsync.htm
3. “Rsync Manual”. SS64. https://ss64.com/bash/rsync.html
4. “How to Use Rsync for Local and Remote Data Transfer and Synchronization”. DigitalOcean. https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories-on-a-vps


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use