深度阅读

How to exclude files and directories from rsync sync?

作者
作者
2023年08月22日
更新时间
9.98 分钟
阅读时间
0
阅读量

To exclude files and directories from an rsync sync, you can use the --exclude option followed by the path of the file or directory you want to exclude. You can use this option multiple times to exclude multiple files or directories.

Here is an example command to exclude a file and a directory during an rsync sync:

rsync -avz --exclude 'file.txt' --exclude 'dir/' /path/to/source/ /path/to/destination/

Explanation of the options used:

  • -a: archive mode, which preserves permissions, ownership, timestamps, and recursive copying
  • -v: verbose output
  • -z: compress file data during transfer to reduce bandwidth usage
  • --exclude: specify a file or directory to exclude from the sync

Note that you can also use patterns with wildcards to exclude multiple files or directories that match a certain pattern. For example, to exclude all .log files in the source directory, you can use:

rsync -avz --exclude '*.log' /path/to/source/ /path/to/destination/

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。