“没有这样的文件或目录”但它存在
我只想从命令行运行可执行文件 ./arm-mingw32ce-g++
,但随后我收到错误消息,
bash: ./arm-mingw32ce-g++: No such file or directory
我正在运行 Ubuntu Linux 10.10。 ls -l
列出
-rwxr-xr-x 1 root root 433308 2010-10-16 21:32 arm-mingw32ce-g++
使用 sudo (sudo ./arm-mingw32ce-g++
) 让
sudo: unable to execute ./arm-mingw32ce-g++: No such file or directory
我不知道为什么操作系统甚至看不到该文件。有什么想法吗?
I simply want to run an executable from the command line, ./arm-mingw32ce-g++
, but then I get the error message,
bash: ./arm-mingw32ce-g++: No such file or directory
I'm running Ubuntu Linux 10.10. ls -l
lists
-rwxr-xr-x 1 root root 433308 2010-10-16 21:32 arm-mingw32ce-g++
Using sudo (sudo ./arm-mingw32ce-g++
) gives
sudo: unable to execute ./arm-mingw32ce-g++: No such file or directory
I have no idea why the OS can't even see the file when it's there. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(21)
正如其他人提到的,这是因为找不到加载程序,而不是您的可执行文件。不幸的是,消息还不够明确。
您可以通过更改可执行文件使用的加载程序来修复它,请参阅我在另一个问题中的完整答案:单个主机上的多个 glibc 库
基本上,您必须找到它尝试使用的加载程序:
然后找到等效加载程序的正确路径,并更改您的可执行文件以使用来自的加载程序它真正的路径:
您可能还需要设置包含的路径,在尝试运行它后您就会知道是否需要它。请参阅其他线程中的所有详细信息。
As mentioned by others, this is because the loader can't be found, not your executable file. Unfortunately the message is not clear enough.
You can fix it by changing the loader that your executable uses, see my thorough answer in this other question: Multiple glibc libraries on a single host
Basically you have to find which loader it's trying to use:
Then find the right path for an equivalent loader, and change your executable to use the loader from the path that it really is:
You will probably need to set the path of the includes too, you will know if you want it or not after you try to run it. See all the details in that other thread.
我收到此错误
“没有这样的文件或目录”
,但它存在,因为我的文件是在 Windows 中创建的,我尝试在 Ubuntu 上运行它,并且该文件包含无效的 15\r(其中包含新行)那里。我刚刚创建了一个新文件,截断了不需要的内容
I got this error
“No such file or directory”
but it exists because my file was created in Windows and I tried to run it on Ubuntu and the file contained invalid 15\r where ever a new line was there.I just created a new file truncating unwanted stuff
添加到此处以供将来参考(供可能遇到相同情况的用户使用):
当在 Windows 上工作(由于行分隔符与 Linux 系统不同,它引入了额外的字符)并尝试在 Linux 中运行此脚本(插入了额外的字符)时,会发生此错误。该错误消息具有误导性。
在 Windows 中,行分隔符是 CRLF (\r\n),而在 Linux 中是 LF (\n)。这通常可以在文本编辑器中选择。
就我而言,这是由于在 Windows 上工作并上传到 Unix 服务器执行而发生的。
Added here for future reference (for users who might fall into the same case):
This error happens when working on Windows (which introduces extra characters because of different line separator than Linux system) and trying to run this script (with extra characters inserted) in Linux. The error message is misleading.
In Windows, the line separator is CRLF (\r\n) whereas in linux it is LF (\n). This can be usually be chosen in text editor.
In my case, this happened due to working on Windows and uploading to Unix server for execution.
对于不存在 32/64 位问题的简单 bash 脚本,我遇到了相同的错误。这可能是因为您尝试运行的脚本中有错误。此 ubuntu 论坛帖子 表明使用普通脚本文件,您可以在前面添加
sh
,您可能会从中得到一些调试输出。例如,看看你是否得到任何输出。
就我而言,实际问题是我尝试执行的文件是 Windows 格式而不是 Linux 格式。
I got the same error for a simple bash script that wouldn't have 32/64-bit issues. This is possibly because the script you are trying to run has an error in it. This ubuntu forum post indicates that with normal script files you can add
sh
in front and you might get some debug output from it. e.g.and see if you get any output.
In my case the actual problem was that the file that I was trying to execute was in Windows format rather than Linux.
我在 Mac 上创建的文件也遇到了同样的问题。
如果我尝试在 shell 中使用 ./filename 运行它,我会收到文件未找到错误消息。
我认为该文件有问题。
我所做的:
打开到服务器的 ssh 会话
cat 文件名
将输出复制到剪贴板
rm 文件名
触摸文件名
vi 文件名
i 表示插入模式
粘贴剪贴板中的内容
ESC 结束插入模式
:wq!
这对我有用。
I had the same problem with a file that I've created on my mac.
If I try to run it in a shell with ./filename I got the file not found error message.
I think that something was wrong with the file.
what I've done:
open a ssh session to the server
cat filename
copy the output to the clipboard
rm filename
touch filename
vi filename
i for insert mode
paste the content from the clipboard
ESC to end insert mode
:wq!
This worked for me.
以下命令适用于 16.4 Ubuntu
当您的 .sh 文件损坏或未按照 Unix 协议进行格式化时,就会出现此问题。
dos2unix 将.sh 文件转换为Unix 格式!
Below command worked on 16.4 Ubuntu
This issue comes when your .sh file is corrupt or not formatted as per unix protocols.
dos2unix converts the .sh file to Unix format!
在
.sh
脚本中,每行必须以单个字符结尾 - 换行符(LF
或“ >\n
”)。不要像我一样犯错误,因为我选择的文本编辑器是 Win 中的 Notepad++。
以Win结尾的默认行是“
\r\n
”(CR LF
),这样的结尾是不是 Linux shell 脚本的标准。In a
.sh
script, each line MUST end with a single character - newline (LF
or "\n
").Don't make mistakes like me, because my text-editor of choice is Notepad++ in Win.
The default line ending in Win is "
\r\n
" (CR LF
), and such ending is not standard for Linux shell scripts.这个:
sed -i -e 's/\r$//' FILE
可能会解决您的问题。正如许多答案已经解释的那样,此问题可能是由 Windows 中的行结尾为
\r\n
引起的,而 Linux 中的行结尾仅为\n
造成的。建议的方法是使用 dos2unix。据我所知,这在大多数 Linux 发行版上并不是标准的,就我而言,我无法安装/使用它。因此我使用了以下方法,(在 Bash 脚本 - “/bin/bash^M:错误的解释器:没有这样的文件或目录”),您可以在其中使用
sed
命令。sed -i -e 's/\r$//' FILE
其中将FILE
替换为文件名,例如sed -i -e ' s/\r$//' myscript.sh
如果您由于某种原因没有安装
sed
但又不想使用dos2unix
您可以使用按照以下步骤安装sed
:This:
sed -i -e 's/\r$//' FILE
, could potentially fix your problem.As many answers already have explained, this issue could be caused by line endings being
\r\n
in Windows and only\n
in Linux. A suggested approach was to usedos2unix
. As far as I understand this is not standard on most Linux distributions, and in my case I could not install / use it.Therefore I used the following approach, (mentioned in Bash script – "/bin/bash^M: bad interpreter: No such file or directory"), where you can use the
sed
command instead.sed -i -e 's/\r$//' FILE
where you replaceFILE
with the name of your file, e.g.sed -i -e 's/\r$//' myscript.sh
If you for some reason do not have
sed
installed but do not want to usedos2unix
you can use the following to installsed
:我刚刚在 mingw32 bash 中遇到了这个问题。我从
Program Files (x86)\nodejs
执行了 node/npm,然后将它们移到disabled
目录中(本质上是从路径中删除它们)。我的路径中还有Program Files\nodejs
(即 64 位版本),但仅在 x86 版本之后。重新启动bash shell后,可以找到64位版本的npm。node
始终正常工作(使用node -v
检查,当 x86 版本移动时,它发生了变化)。我认为 bash -r 会起作用,而不是重新启动 bash: https://unix.stackexchange.com /a/5610
I just had this issue in
mingw32 bash
. I had execuded node/npm fromProgram Files (x86)\nodejs
and then moved them intodisabled
directory (essentially removing them from path). I also hadProgram Files\nodejs
(ie. 64bit version) in path, but only after the x86 version. After restarting the bash shell, the 64bit version of npm could be found.node
worked correctly all the time (checked withnode -v
that changed when x86 version was moved).I think
bash -r
would've worked instead of restarting bash: https://unix.stackexchange.com/a/5610我遇到了这个问题,原因是某些编辑器(例如 Notepad++)已停产。您可以在编辑菜单/EOL 转换中检查它。应选择 Unix(LF)。
我希望它会有用。
I had this issue and the reason was EOL in some editors such as Notepad++. You can check it in Edit menu/EOL conversion. Unix(LF) should be selected.
I hope it would be useful.
尝试运行 terraform/terragrunt (单向二进制)时遇到此错误。
使用
which terragrunt
查找可执行文件的位置,在本地目录或使用完整路径运行它时出现奇怪的错误问题是有两个 terragrunt 安装,使用
brew uninstall terragrunt
删除一个固定它。删除后,
which terragrunt
显示了新路径/usr/bin/terragrunt
一切正常。Hit this error trying to run terraform/terragrunt (Single go binary).
Using
which terragrunt
to find where executable was, got strange error when running it in local dir or with full pathProblem was that there was two installations of terragrunt, used
brew uninstall terragrunt
to remove one fixed it.After removing the one,
which terragrunt
showed the new path/usr/bin/terragrunt
everything worked fine.对于那些在运行 java 程序时遇到此错误的人,可能是您尝试在 32 位 Linux 操作系统上运行 64 位 java 程序。
当我在 64 位 java 上运行 ldd 时我才意识到其中报告:
ldd /usr/java/jdk1.8.0_05/bin/java
'不是动态可执行文件'
而旧的 32 位 java 报告了合理的结果:
ldd /usr/java/jdk1.8.0_05/bin/java
For those encountering this error when running a java program, it's possible that you're trying to run a 64-bit java program using on a 32-bit linux operating system.
I only realised when I ran ldd on 64-bit java which reported:
ldd /usr/java/jdk1.8.0_05/bin/java
'not a dynamic executable'
Whereas the old 32 bit java reported sensible results:
ldd /usr/java/jdk1.8.0_05/bin/java
就我而言,事实证明该文件是一个符号链接:
像这样的误导性错误在 Linux 上相当常见。相关讨论:https://lwn.net/Articles/532771/
In my case, it turns out the file was a symlink:
Misleading errors like this are fairly common on Linux. Related discussion: https://lwn.net/Articles/532771/
对于未来的读者,我在尝试使用 Gunicorn 启动 Django 服务器时遇到了这个问题。我使用 AWS CodeBuild 构建虚拟环境并运行测试,并使用 CodeDeploy 将构建的工件放到生产服务器上并启动新版本(所有环境都是 Ubuntu 20.04)。我错误地认为 env/bin/... 包含本机库的实际二进制文件,但事实并非如此。它只是 Python 脚本,带有构建机器上 Python 解释器的路径。就我而言,安装软件包和实际运行软件包的机器是不同的。更具体地说,
env/bin
中的所有文件都有 shebang#!/codebuild/output/src715682316/src/env/bin/python
,所以当然在生产服务器上运行 env/bin/gunicorn 将会失败。神秘的错误消息是 Ubuntu 告诉我env/bin/gunicorn
不存在,而不是说/codebuild/output/src715682316/src/env/bin/python
代码> 不存在。我能够通过使用python3 env/bin/gunicorn
而不是env/bin/gunicorn
启动 Gunicorn 来解决此问题。For future readers, I had this issue when trying to launch a Django server using gunicorn. I was using AWS CodeBuild to build the virtual environment and run tests and using CodeDeploy to put the built artifacts onto the production server and launch the new version (all environments were Ubuntu 20.04). I had mistakenly thought that
env/bin/...
contained actual binaries of native libraries but that was not the case. It was just Python scripts with a shebang of the path to the Python interpreter on the build machine. In my case, the machine installing the packages and actually running the packages was different. To be more specific, all of the files inenv/bin
had the shebang#!/codebuild/output/src715682316/src/env/bin/python
, so of course runningenv/bin/gunicorn
on the production server would fail. The cryptic error message was when Ubuntu would tell me thatenv/bin/gunicorn
didn't exist as opposed to saying/codebuild/output/src715682316/src/env/bin/python
didn't exist. I was able to fix this problem by starting gunicorn usingpython3 env/bin/gunicorn
instead ofenv/bin/gunicorn
.另一个可能的原因:该文件是一个动态链接到
debian 系统上的
musl
(最有可能是 alpine)的二进制文件,您必须安装Yet another possible reason: the file is a binary linked dynamically against
musl
(most likely for alpine)on debian system you will have to install
不是同样的问题,但可能对某些人有帮助
我的脚本:
我的主目录中有 blabla,但
错误消息:
./b.sh:第 3 行:calm-cat=/home/bob/blabla:否这样的文件或目录
是因为shell脚本变量名不能包含破折号(-)
所以将其更改为
calm_cat
将解决该问题not the same problem, but maybe helpful for some people
my script:
i have blabla in my home directory, but
error message:
./b.sh: line 3: calm-cat=/home/bob/blabla: No such file or directory
it's because shell script variable name can't contain dash (-)
so change it to
calm_cat
will solve that problem此错误可能意味着
./arm-mingw32ce-g++
不存在(但确实存在),或者它存在并且是内核识别的动态链接可执行文件,但其动态加载器不可用。运行ldd /arm-mingw32ce-g++
就可以看到需要什么动态加载器;任何标记为“未找到”的内容都是您需要安装的动态加载程序或库。如果您尝试在 amd64 安装上运行 32 位二进制文件:
ia32-libs
。ia32-libs-multiarch
。ia32-libs-multiarch
,或选择合理的除了:amd64
包之外的一组:i386
包。This error can mean that
./arm-mingw32ce-g++
doesn't exist (but it does), or that it exists and is a dynamically linked executable recognized by the kernel but whose dynamic loader is not available. You can see what dynamic loader is required by runningldd /arm-mingw32ce-g++
; anything markednot found
is the dynamic loader or a library that you need to install.If you're trying to run a 32-bit binary on an amd64 installation:
ia32-libs
.ia32-libs-multiarch
.ia32-libs-multiarch
, or select a reasonable set of:i386
packages in addition to the:amd64
packages.当我尝试在 Ubuntu 上构建 Selenium 源代码时,我遇到了这个错误。即使我满足了所有先决条件,具有正确 shebang 的简单 shell 脚本也无法运行。
我在 Vim 中打开这个文件,我可以看到,因为我曾经在 Windows 机器上编辑过这个文件,所以它是 DOS 格式的。我使用以下命令将文件转换为 Unix 格式:
我希望我们在跨平台编辑文件时应该小心,我们也应该注意文件格式。
I faced this error when I was trying to build Selenium source on Ubuntu. The simple shell script with correct shebang was not able to run even after I had all pre-requisites covered.
I opened the file in Vim and I could see that just because I once edited this file on a Windows machine, it was in DOS format. I converted the file to Unix format with below command:
I hope that we should take care whenever we edit files across platforms we should take care for the file formats as well.
如果尝试运行脚本并且 shebang 拼写错误,也可能会出现此错误。确保它读取
#!/bin/sh
、#!/bin/bash
或您使用的任何解释器。This error may also occur if trying to run a script and the shebang is misspelled. Make sure it reads
#!/bin/sh
,#!/bin/bash
, or whichever interpreter you're using.当我尝试运行 Python 脚本时,我遇到了同样的错误消息——这不是 @Warpspace 的预期用例(请参阅其他评论),但这是我搜索的热门搜索之一,所以也许有人会发现它有用。
就我而言,shebang 行 (
#!/usr/bin/env python
)会被绊倒。一个简单的dos2unix myfile.py
修复了它。I had the same error message when trying to run a Python script -- this was not @Warpspace's intended use case (see other comments), but this was among the top hits to my search, so maybe somebody will find it useful.
In my case it was the DOS line endings (
\r\n
instead of\n
) that the shebang line (#!/usr/bin/env python
) would trip over. A simpledos2unix myfile.py
fixed it.我在此处找到了适用于 Ubuntu 18 的解决方案。
然后:
I found my solution for my Ubuntu 18 here.
Then: