我有一个rsync命令用于将我的文件从开发复制到生产.我不想复制
HTML目录根目录中的.htaccess文件,但我想复制其子目录中的几个.htaccess文件.
我正在使用参数–exclude .htaccess来阻止所有文件被复制.我包括的其他参数是-a –recursive –times –perms.是否可以配置rsync来执行此操作?
编辑:
这是我的完整命令:
rsync -a --recursive --times --perms \ --exclude prop_images --exclude tracking --exclude vtours \ --exclude .htaccess --exclude .htaccess_backup --exclude "*~" \ /home/user/dev_html/* /home/user/public_html/
解决方法
指定–exclude .htaccess时,将排除以.htaccess结尾的任何路径.
要仅排除传输源根目录下的.htaccess,您需要–exclude /.htaccess
从rsync手册页,一些更详细的信息和对其他阅读的参考:
- if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files,otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus “/foo” would match a file named “foo” at either the “root of the transfer” (for a global rule) or in the merge-file’s directory (for a per-directory rule). An unqualified “foo” would match any file or directory named “foo” anywhere in the tree because the algorithm is applied recursively from the top down; it behaves as if each path component gets a turn at being the end of the file name. Even the unanchored “sub/foo” would match at any point in the hierarchy where a “foo” was found within a directory named “sub”. See the section on ANCHORING INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a pattern that matches at the root of the transfer.