- How to Fix “bash: no such file or directory”
- How to Resolve the “no such file or directory”?
- Reason 1: Wrong File Name
- Solution: Check the File name and Path
- Reason 2: Wrong File Format
- Solution: Use the dos2unix Tool
- Conclusion
- Running executable file: No such file or directory [closed]
- 1 Answer 1
- «No such file or directory» error when trying to execute a binary [duplicate]
- 2 Answers 2
- sudo: unable to execute ./script.sh: no such file or directory
How to Fix “bash: no such file or directory”
Unlike other operating systems such as Windows, Linux is an OS in which the majority of its tasks are performed using the Terminal. One of the major tasks that the Linux terminal performs is the execution of programs using commands. While attempting to execute any program through this method, the user may come across this very common error statement which is the “no such file or directory” issue.
This article will elaborate on the reasons that prompt the error “no such file or directory” and also provide possible solutions to fix it
How to Resolve the “no such file or directory”?
Since this is a very general error, there are a few different reasons that can invoke this issue on the system. All these reasons are discussed below in great detail.
Reason 1: Wrong File Name
The first and the most commonly occurring reason is caused by using incorrect spellings of the file name. For example, the mistake can be the incorrect spelling of a file. Below is an example of such a mistake:
Solution: Check the File name and Path
In the example shown above, the bash file “sample.sh” is saved on the desktop. So, make sure that the error is not invoked by using the correct spellings and the correct path. Look at the following image where the name and path of the file are correct, and thus, the output is displayed:
Reason 2: Wrong File Format
The other most common cause behind this issue is that the file that is attempted to execute is in a different format than the operating system. Let’s take an example of this situation. The file that is executed using the command is a DOS file which is a script written for Windows. If this DOS file is executed in an Ubuntu system, the “no such file or directory” issue will be invoked.
Solution: Use the dos2unix Tool
There exists a very useful tool for exactly these types of scenarios. The dos2unix tool helps to convert a dos file to a script that can be read by the Ubuntu OS. The first step is to install the dos2unix tool using this command:
$ sudo apt install dos2unix
Once the tool is installed, convert the DOS file into an Ubuntu-compatible file using the following command:
The system should be able to run the script file without the error being prompted after the conversion is complete.
Conclusion
The “no such file or directory” issue occurs when the name or the path of the executable file is entered incorrectly into the terminal. Another reason is that Ubuntu is not able to read the DOS script and if it is executed on the Ubuntu terminal, then the error is prompted. To fix these issues it needs to be made sure that the file path and file name are entered correctly into the terminal. The other fix is to install the dos2unix tool and convert the dos files format to run on Ubuntu. This article has demonstrated the reasons and the solutions to fix the error “no such file or directory”.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY
Running executable file: No such file or directory [closed]
Questions describing a problem that can’t be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers.
I am trying to run an executable file called i686-elf-gcc in my Kali Linux that I downloaded from this repository. It’s a cross-compiler. The problem is that even though the terminal and a script that I wrote can both see that the file exists, when its time to actually execute it I get No such file or directory error.Here is an image that explains it: I have also to say that I have granted the necessary permissions to the executable.
You are already logged in as root . Can you please explain me the reason for running the command with sudo ?
It will help hardly anyone. You’ve posted a non-indexable image instead of text, not given a correct description of the problem, handwaved over what you did to fix it, and not even supplied your answer as an actual answer.
1 Answer 1
Typically, the «unable to execute. No such file or directory» means that either the executable binary itself or one of the libraries it needs does not exist. Libraries can also need other libraries themselves.
To see a list of libraries required by a specified executable or library, you can use the ldd command:
$ ldd /usr/local/bin/i686-elf-gcc
If the resulting listing includes lines like
then the problem can be fixed by making sure the mentioned libraries are installed and in the library search path.
In this case, the libraries might be at /usr/local/lib or /usr/local/lib64 , but for some reason that directory is not included in the library search path.
If you want the extra libraries to be available for specific programs or sessions only, you could use the LD_LIBRARY_PATH environment variable to identify the extra path(s) that should be searched for missing libraries. This will minimize the chance of conflicts with the system default libraries.
But if you want to add a library directory to the system default library search path, you should add it to /etc/ld.so.conf file, or create a /etc/ld.so.conf.d/*.conf file of your choice and then run the ldconfig command as root to update the library search cache.
For example, if the missing libraries are found in /usr/local/lib64 and /etc/ld.so.conf.d directory exists, you might want to create crosscompiler.conf file like this:
# echo "/usr/local/lib64" > /etc/ld.so.conf.d/crosscompiler.conf # ldconfig
«No such file or directory» error when trying to execute a binary [duplicate]
nasm -f elf64 test64.asm successfully creates test64.o and ld -s -o hello test64.o -lc creates an executable file, but when I try to run it, I get a «No such file or directory» error.
Regarding the edit — I’m adding Linux tag back in. This code, is compiled with NASM; is about running executables in a Linux like environment (confirmed with the fact we are tagged as Ubuntu); and the linker target is ELF64. I would suggest that given that information, that Linux is still an applicable tag because it is a question about software development in a Linux environment, and to fix the issue will require a Linux specific solution.
2 Answers 2
1) You’re using the wrong calling convention for printf . The arguments were passed in registers, not on the stack: https://en.wikipedia.org/wiki/X86_calling_conventions#System_V_AMD64_ABI. Also, printf needs a value in EAX (0 in your case).
is wrong. But if you use the 64-bit-Linux-syscall
mov edi, 0 ; return 0 (success) mov eax, 60 ; sys_exit syscall
you will not see the output of printf , because it is buffered and the buffer won’t be flushed. You can call fflush(0) or exit .
3) To use C functions in Linux you have to link with a special loader ( /lib64/ld-linux-x86-64.so.2 ). I just don’t know if it is installed by default.
4) push val1 pushes the address of val1, not its value. Use brackets to get the values. I guess you wanted just load a 32-bit DWORD into a 64-bit register. You can directly load the DWORD into a 32-bit register (the upper part of the 64-bit-register will be cleared) or use movsx for a signed operation.
section .data fmt db `%d\n`,0 ; backticks for '\n' val1 dd 23 val2 dd 9 val3 dd 7 section .text global _start extern printf, exit _start: movsx rax, dword [val1] ; signed dword to signed qword movsx rbx, dword [val2] imul rax, rbx mov ebx, [val3] ; unsigned dword into RBX add rax, rbx mov [val1], rax mov rdi, fmt ; string pointer mov rsi, [val1] ; immediate value xor eax, eax ; no vector registers used call printf xor edi, edi call exit
nasm -f elf64 test64.asm
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test64 test64.o -lc
./test64
sudo: unable to execute ./script.sh: no such file or directory
[user@server ~]$ ll total 4 -rwx------ 1 user user 2608 Jul 15 18:23 qa.sh
[user@server ~]$ sudo ./qa.sh [sudo] password for user: sudo: unable to execute ./qa.sh: No such file or directory
This is on a fresh build. No changes have been made which would cause problems. In fact, the point of the script is to ensure that it is actually built according to our policies. Perhaps maybe it isn’t and sudo is actually being broken during the build? I should also note that I can run sudo with other commands in other directories. EDIT: The script ( I didn’t write it so don’t /bin/bash me over it, please 😉 )
#! /bin/bash . /root/.bash_profile customer=$1 if [ -z "$customer" ]; then echo "Customer not provided. Exiting. " exit 1 fi space () < echo echo '###########################################################################' echo '###########################################################################' echo '###########################################################################' echo >g=/bin/egrep $g ^Listen /etc/ssh/sshd_config $g ^PermitR /etc/ssh/sshd_config $g ^LogL /etc/ssh/sshd_config $g ^PubkeyA /etc/ssh/sshd_config $g ^HostbasedA /etc/ssh/sshd_config $g ^IgnoreR /etc/ssh/sshd_config $g ^PermitE /etc/ssh/sshd_config $g ^ClientA /etc/ssh/sshd_config space $g 'snyder|rsch|bream|shud|mweb|dam|kng|cdu|dpr|aro|pvya' /etc/passwd ; echo ; echo ; $g 'snyder|rsch|bream|shud|mweb|dam|kng|cdu|dpr|aro|pvya' /etc/shadow space $g 'dsu|scan' /etc/passwd ; echo ; echo ; $g 'dsu|scan' /etc/shadow space $g $admin /etc/passwd space chage -l $admin space $g 'urs|cust|dsu' /etc/sudoers space $g dsu /etc/security/access.conf space $g account /etc/pam.d/login space /sbin/ifconfig -a | $g addr | $g -v inet6 space echo "10.153.156.0|10.153.174.160|10.120.80.0|10.152.80.0|10.153.193.0|172.18.1.0|10.153.173.0" echo $g '10.153.156.0|10.153.174.160|10.120.80.0|10.152.80.0|10.153.193.0|172.18.1.0|10.153.173.0' /etc/sysconfig/network-scripts/route-eth1 space cat /etc/sysconfig/network-scripts/route-eth2 space netstat -rn | tail -1 space cat /etc/sysconfig/iptables space cat /etc/hosts space ##file /usr/local/groundwork ; echo ; echo ; /sbin/service gdma status ##space cat /etc/resolv.conf space HOSTNAME=`echo $HOSTNAME | awk -F. '< print $1 >'` nslookup $ echo echo nslookup $-mgt echo echo nslookup $-bkp space /sbin/service rhnsd status ; echo ; echo ; /sbin/chkconfig --list rhnsd ; echo ; echo ; yum update --security space /sbin/service osad status ; echo ; echo ; /sbin/chkconfig --list osad space /sbin/service sshd status ; echo ; echo ; /sbin/chkconfig --list sshd space /sbin/service snmpd status ; echo ; echo ; /sbin/chkconfig --list snmpd ; echo ; echo ; echo ; cat /etc/snmp/snmpd.conf space df -h space cat /proc/cpuinfo | $g ^processor space free -g space if [ -f /etc/rsyslog.conf ]; then tail -3 /etc/rsyslog.conf else echo "This system is not running rsyslog." fi rm -f $0