0

The manual does not specify (nor exclude for that matter) whether I can specify on the command line --exclude-from=FILE multiple times, like so:

rsync -av --exclude-from=FILE1 --exclude-from=FILE2 source destination

So is it possible to specify different exclude files?

2

Yes, you can use --exclude-file multiple times to specify different exclude files. And this can be helpful if you want to separate the different class of files into separate exclude files.

This is the directory structure and I have to remove the executable and the temp files generated.

root-dir/
├── dir1
│   ├── dir1-1
│   │   ├── a.out
│   │   └── file1.txt
│   └── dir1-2
│       ├── a.out
│       └── file2.txt
├── dir2
│   └── dir2-1
│       ├── a.out
│       ├── file3.txt
│       └── README.md
└── dir3
    ├── dir3-1
    │   └── a.exe
    ├── dir3-2
    │   ├── a.out
    │   ├── program1.cpp
    │   ├── program1.ii
    │   ├── program1.o
    │   └── program1.s
    └── dir3-3
        ├── a.out
        ├── program2.cpp
        ├── program2.ii
        ├── program2.o
        └── program2.s

Use the command

rsync --exclude-from exclude-exec --exclude-from exclude-temps -av SRC/ DEST/

exclude-exec contains

*.out
*.exe

exclude-temps contains

*.ii
*.o
*.s

The directory structure after the operation becomes,

root-dir/
├── dir1
│   ├── dir1-1
│   │   └── file1.txt
│   └── dir1-2
│       └── file2.txt
├── dir2
│   └── dir2-1
│       ├── file3.txt
│       └── README.md
└── dir3
    ├── dir3-1
    ├── dir3-2
    │   └── program1.cpp
    └── dir3-3
        └── program2.cpp
  • Confirmed. The question is of the type you can answer just by trying and reviewing the result; therefore I was surprised to see the answer is not from the asker. +1 for you who took the effort. – Kamil Maciorowski Nov 28 '17 at 7:11
  • @KamilMaciorowski getting an answer here will confirm that it will work across all distros but also helps me to understand the confusion in the man page and it's use of OR (which is wrong): "Note also that the --filter, --include, and --exclude options take one rule/pattern each. To add multiple ones, you can repeat the options on the command-line, use the merge-file syntax of the --filter option, or the --include-from/--exclude-from options." The last "or" could mean you either need to use many ''excludes'' or ONE exclude file, but does not confirm multiple uses of --exclude-from. – Jobst Nov 29 '17 at 0:02

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.