bash chmod: 无法访问 '\r': 没有那个文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22825460/
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-18 10:05:40  来源:igfitidea点击:

chmod: cannot access ‘\r’: No such file or directory

linuxbash

提问by Tony

I have these 2 line in my aaa.shfile:

我的aaa.sh文件中有这两行:

#!/bin/bash
chmod +x  /home/tot/*.html

When I run it on AWS EC2 Linux:

当我在 AWS EC2 Linux 上运行它时:

$ sh aaa.sh

I got this message:

我收到了这条消息:

chmod: cannot access ‘\r': No such file or directory

回答by nobody

You have Windows line endings in your file (\r\n). It needs to have Unix-style line endings (\n only).

您的文件中有 Windows 行结尾 (\r\n)。它需要有 Unix 风格的行尾(仅限 \n)。

You can do the conversion with the common dos2unixutility, or the set ff=unixcommand in vim.

您可以使用通用dos2unix实用程序或set ff=unixvim 中的命令进行转换。

回答by Jimko

chmod shouldn't care about the contents of your files. I bet you have a file with a control character in the filename itself. Might display as a question mark, but ls -b *.htmlshould show you the culprit. Are your sure you wantexecutable html files?

chmod 不应该关心文件的内容。我敢打赌你有一个文件名本身带有控制字符的文件。可能会显示为问号,但ls -b *.html应该向您展示罪魁祸首。你确定你想要可执行的 html 文件吗?