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
chmod: cannot access ‘\r’: No such file or directory
提问by Tony
I have these 2 line in my aaa.sh
file:
我的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 dos2unix
utility, or the set ff=unix
command in vim.
您可以使用通用dos2unix
实用程序或set ff=unix
vim 中的命令进行转换。
回答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 *.html
should show you the culprit. Are your sure you wantexecutable html files?
chmod 不应该关心文件的内容。我敢打赌你有一个文件名本身带有控制字符的文件。可能会显示为问号,但ls -b *.html
应该向您展示罪魁祸首。你确定你想要可执行的 html 文件吗?