Dino Geek, try to help you

How to exclude multiple directories with RSYNC?


RSYNC, short for ‘remote synchronization’, is a powerful tool in Unix/Linux that allows the user to make backups, mirror systems or even run scripts to update multiple machines at once. As is typical with these types of tools, RSYNC offers a lot of flexibility and customization to users. One such customization is the ability to exclude multiple directories when running a command.

To exclude multiple directories with RSYNC, you utilize the ‘—exclude’ flag in the command line. If you specify this flag followed by a directory name, RSYNC will then exclude that directory when running.

An example would look like this:

```
rsync -a —exclude ‘dir1’ —exclude ‘dir2’ source/ destination/
```
In this case, ‘dir1’ and ‘dir2’ are the names of the directories you wish to exclude from the RSYNC command. The ‘source/’ is the directory from which you are copying, and ‘destination/’ is where you are copying to. The ‘-a’ option is a handy shortcut for a bundle of options (‘-rlptgoD’) which preserve symbolic links, file permissions, modification times, group, owner, and device files.

However, if you have many directories to exclude, typing them out one at a time is inefficient. Instead, you can create a file, ‘exclude.txt’ for example, where each line in the file is a directory to be excluded.

The updated command is as follows:

```
rsync -a —exclude-from=‘exclude.txt’ source/ destination/
```
In this command, exclude.txt contains the list of directories to be excluded.

This ‘-exclude-from’ option allows you to specify a file from which to gather directories to exclude, rather than inputting them manually. This saves considerable time and allows for easy updating by simply changing the ‘exclude.txt’ file.

To illustrate, if you have a ‘dir1’, ‘dir2’, and ‘dir3’ directories to exclude, your exclude.txt file would look like this:

```
dir1
dir2
dir3
```
These commands and options for excluding directories, and more, are detailed in the RSYNC man page (`man rsync`).

Note that RSYNC interprets the path you provide relative to the source directory. For instance, if you’re backing up the directory `/home/user` and you want to exclude `/home/user/dir1`, in your exclude.txt file or your —exclude option, you should specify `dir1`, not `/home/user/dir1`.

Remember to test your command with the `-n` or `—dry-run` option before executing it. This will provide a list of the files that would be transferred but does not create any files on the destination.

In conclusion, with ‘—exclude’ or ‘—exclude-from’ commands, you can avoid unwanted directories to ensure a smooth sync with RSYNC.

Source:

- https://linux.die.net/man/1/rsync
- https://www.tecmint.com/rsync-local-remote-file-synchronization-commands/
-https://www.howtoforge.com/tutorial/rsync-exclude-files-and-folders/


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