How to exclude file when using scp command recursively
How to use rsync command to exclude files
The syntax is:rsync -av -e ssh --exclude='*.out' /path/to/source/ user@hostB:/path/to/dest/
Where,
- -a : Recurse into directories i.e. copy all files and subdirectories. Also, turn on archive mode and all other options (-rlptgoD)
- -v : Verbose output
- -e ssh : Use ssh for remote shell so everything gets encrypted
- --exclude='*.out' : exclude files matching PATTERN e.g. *.out or *.c and so on.
Example of rsync command
In this example copy all file recursively from ~/virt/ directory but exclude all *.new files:$ rsync -av -e ssh --exclude='*.new' ~/virt/ root@centos7:/tmp
Sample outputs: