Bash 脚本 rsync: rsync: link_stat (blah) failed: No such file or directory (2)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10726236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:08:41  来源:igfitidea点击:

Bash scripting rsync: rsync: link_stat (blah) failed: No such file or directory (2)

bashscriptingrsync

提问by Nathaniel Ford

I am trying to write a simple bash script for my local (Mac OS X) machine to move files from a directory on my machine to a remote machine. This line is failing:

我正在尝试为我的本地 (Mac OS X) 机器编写一个简单的 bash 脚本,以将文件从我机器上的目录移动到远程机器。此行失败:

rsync --verbose  --progress --stats --compress --rsh=ssh \
      --recursive --times --perms --links --delete \
      --exclude "*bak" --exclude "*~" \
      /repository/* $DEV_SERVER:$REMOTE_DIR

$DEV_SERVERand $REMOTE_DIRare defined previously, and I echo them to verify they're accurate.

$DEV_SERVER$REMOTE_DIR之前定义的,我回应它们以验证它们是准确的。

The error I'm getting is:

我得到的错误是:

rsync: link_stat /Users/myusername/mycurrentdirectory failed: No such file or directory (2)

To note here is that rather than using the defined directory (/repository, which is in the root of the machine), it uses my working directory. What is causing this?

这里要注意的是/repository,它使用我的工作目录,而不是使用定义的目录(位于机器的根目录中)。这是什么原因造成的?

回答by Martin Smith

Check that your \ characters have no whitespace after then at the end of the line, because this will cause BASH to not interpret the line wrap correctly, giving the rsync error above

检查你的 \ 字符在行尾之后是否没有空格,因为这会导致 BASH 无法正确解释换行,从而导致上面的 rsync 错误

回答by garry_g

Remove the '*' from the source location, rsync knows to look in the inside of the directory if you specify the '/' in the end

从源位置删除“*”,如果您在最后指定“/”,rsync 知道查看目录内部

like that:

像那样:

rsync --verbose  --progress --stats --compress --rsh=ssh --recursive --times --perms --links --delete --exclude "*bak" --exclude "*~" /repository/ $DEV_SERVER:$REMOTE_DIR

回答by Nathaniel Ford

This:

这个:

rsync --verbose  --progress --stats --compress --rsh=ssh \
  --recursive --times --perms --links --delete \
  --exclude "*bak" --exclude "*~" \
  /repository/* $DEV_SERVER:$REMOTE_DIR

should be this:

应该是这样的:

rsync --verbose  --progress --stats --compress --rsh=ssh --recursive --times --perms --links --delete --exclude "*bak" --exclude "*~" /repository/* $DEV_SERVER:$REMOTE_DIR

Bash interprets the \character differently than the command line, or perhaps there is an implicit non-whitespace character after it.

Bash 对\字符的解释与命令行不同,或者它后面可能有一个隐含的非空白字符。