4

I'm having a weird problem where I have an executable in a directory, but when I try to run it, bash says that it doesn't exist:

kiarashsadr@pandoras-box:~/Downloads/Tether/linux$ ls
adb  run.sh

kiarashsadr@pandoras-box:~/Downloads/Tether/linux$ ls -l
total 1204
-rwxrwxr-x 1 kiarashsadr kiarashsadr 1226659 Mar  9  2013 adb
-rwxrwxr-x 1 kiarashsadr kiarashsadr     521 Oct 29  2012 run.sh

kiarashsadr@pandoras-box:~/Downloads/Tether/linux$ ./adb
bash: ./adb: No such file or directory

output from file:

kiarashsadr@pandoras-box:~/Downloads/Tether/linux$ file adb
adb: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped

wut??

Sean Bright
  • 118,630
  • 17
  • 138
  • 146
dsynkd
  • 1,999
  • 4
  • 26
  • 40
  • Show `ls -l` output. Maybe there's a funny character in the name?b Maybe show the first 3 lines or so of the file — if there's a shebang line and that's malformed, you can get that because the command interpreter can't be found. – Jonathan Leffler Sep 17 '15 at 20:39
  • Your `adb` is a 1.2 MiB script? Or an executable program? Scripts are text files. That looks like it is probably an executable. And if so, what do you get from `file ./adb /bin/sh`? Are they the same type? – Jonathan Leffler Sep 17 '15 at 20:42
  • adb is an executable (binary) file. what do you mean by the first 3 lines? – dsynkd Sep 17 '15 at 20:43
  • right, it's an executable. I mistakenly said script. – dsynkd Sep 17 '15 at 20:43
  • 2
    I seem to recall that this error pops up when the loader can't find a dynamic lib which the executable references. Is that possible? – Peter - Reinstate Monica Sep 17 '15 at 20:45
  • Looking at the first three lines of an executable is not a good idea; cancel that — but I was misled by the wording in the question. What does `file` have to say? – Jonathan Leffler Sep 17 '15 at 20:46
  • @Peter: I imagine bash is just calling `perror("bash: ./adb")` and doesn't differentiate between "the executable is missing" and "I can't find libc (or whatever)." – Kevin Sep 17 '15 at 20:46
  • 2
    This question's answers http://unix.stackexchange.com/questions/120015/how-to-find-out-the-dynamic-libraries-executables-loads-when-run show how to get a list of referenced libraries. – Peter - Reinstate Monica Sep 17 '15 at 20:50
  • ldd says that it's "not a dynamic executable" – dsynkd Sep 17 '15 at 20:52
  • One could also call [`explain_execve_or_die(3)`](http://linux.die.net/man/3/explain_execve_or_die), which should either work or produce a more useful error message. Naturally, this requires a C compiler and might not be portable (is libexplain POSIX standard?). – Kevin Sep 17 '15 at 20:52
  • 1
    Are you trying to run a 32-bit program on a 64-bit system? – melpomene Sep 17 '15 at 20:57
  • ^ that's what I was just about to say is probably the case... – dsynkd Sep 17 '15 at 20:57
  • I'm running Ubuntu 14.04 64-bit. – dsynkd Sep 17 '15 at 20:59
  • Related: http://stackoverflow.com/questions/8752727/executing-32-bit-code-under-ubundu-64-bit-installation-error-no-such-file-or-di – melpomene Sep 17 '15 at 21:00
  • Feel free to add that as an answer. I'm currently reading http://askubuntu.com/questions/454253/how-to-run-32-bit-app-in-ubuntu-64-bit – dsynkd Sep 17 '15 at 21:02

2 Answers2

5

You're trying to run a 32-bit executable on a 64-bit system. Bash doesn't differentiate between this case and "no such file or directory" case.

More about this topic: Executing 32 bit code under Ubundu 64 bit installation error- No such file or directory

More on how to run 32-bit executables on 64-bit systems: https://askubuntu.com/questions/454253/how-to-run-32-bit-app-in-ubuntu-64-bit

Community
  • 1
  • 1
dsynkd
  • 1,999
  • 4
  • 26
  • 40
  • I can confirm the error you get in that case is exactly 'no such file or directory', as if the file wasn't there. – LSerni Sep 17 '15 at 21:24
1

As stated by VOR73X, the reason in this case is that the file is a 32-bit executable on a 64-bit architecture. You can run it, but you need a compatibility layer to do so. If you have it:

mintaka:/home/lserni # file ansi
ansi: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.2.5, not stripped
mintaka:/home/lserni # uname -a
Linux mintaka 4.0.1-1-default #1 SMP Wed Apr 29 15:04:53 UTC 2015 (e3a374a) x86_64 x86_64 x86_64 GNU/Linux
mintaka:/home/lserni # ./ansi
Syntax: ansi [file|-]

...and otherwise you get 'no such file or directory'.

However, there might be other reasons to be unable to run a file that "seems" to be there (or even is).

Missing dynamic libraries would give a distinctive error (at least they do on my system, Linux OpenSuSE 13.2):

./test: error while loading shared libraries: libcap.so.2: cannot open shared object file: No such file or directory

Another possibility...

...is that the file is not named as you think it is. The file you asked for is really not there!

For example (using the same obsolete file as before)

mintaka:/home/lserni # mv ansi 'ansi '
mintaka:/home/lserni # ls -la ansi*
-rwxr-xr-x 1 root root 14268 Sep 17 23:29 ansi

The file seems to be there but its name now ends with a space, so as you would expect...

mintaka:/home/lserni # ./ansi
bash: ./ansi: No such file or directory

Of course if the file is called correctly, escaping the space...

mintaka:/home/lserni # ./ansi\
Syntax: ansi [file|-]
mintaka:/home/lserni #

Other tricks are possible (I did it to myself once by mistake and have seen some worm using this trick to hide from a casual 'ls'). For example UTF8 invisible characters.

Try

ls -la | hexdump -C

to verify that the name is indeed what it ought to be.

LSerni
  • 55,617
  • 10
  • 65
  • 107