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”?
- Reason 1: Wrong File Name
- Solution: Check the File name and Path
- Reason 2: Wrong File Format
- Solution: Use the dos2unix Tool
- Conclusion
- Вступление
- Причина возникновения
- Как исправить ошибку (способ 1: очень быстрый)
- Как исправить ошибку (способ 2: медленный, но очень надежный)
- Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Re: Boot failing: No init found
- Минуточку внимания
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:
$ bash sampl.sh

Solution: Check the File name and Path
$ bash sample.sh

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

$ dos2unix sample.dos

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”.
Debian, Linux, Ubuntu
- 17.03.2021
- 15 433
- 23
- 1
Вступление
Иногда при запуске различных sh скриптов можно столкнуться вот с такой ошибкой:
bash: ./script.sh: /bin/bash^M: bad interpreter: No such file or directory
В данной статье мы рассмотрим причину возникновения данной ошибки и о способах ее исправления.
Причина возникновения
Как видно из текста ошибки, при запуске скрипта вместо стандартного шелла /bin/bash
скрипт пытается запустить его из директории /bin/bash^M
и ожидаемо выдает ошибку, потому что такого пути не существует. Все дело в том, что ^M
— это символ возврата каретки (окончания строки), который обычно используется на Windows системах. По всей видимости, данный скрипт редактировался каким-либо текстовым редактором, в настройках которого был выставлен режим Windows (а не Linux) и из-за этого, при запуске скрипта получается такая ошибка.
Как исправить ошибку (способ 1: очень быстрый)
Допустим, наш скрипт, при запуске которого мы получаем ошибку будет называться script.sh
.
1) Делаем его резервную копию, чтобы иметь возможность восстановить работоспособность, если что-либо пойдет не так.
2) Запускаем следующую команду:
sed -i -e 's/\r$//' script.sh
Она должна заменить все символы переноса строки Windows на те, которые используются на Linux системах. Способ не совсем универсальный, поэтому иногда может не сработать.
3) После выполнения данной команды, пытаемся запустить на скрипт script.sh
и проверить работоспособность. Если не помогло, то восстанавливаем оригинал из резервной копии и переходим ко второму способу.
Как исправить ошибку (способ 2: медленный, но очень надежный)
Если первый способ не помог, либо если вы часто сталкиваетесь с такой ошибкой, то можно воспользоваться специальной утилитой dos2unix
, которая как раз подходит для таких случаев
1) Делаем резервную копию script.sh
, чтобы восстановить его в случае проблем.
2) Устанавливаем утилиту dos2unix
sudo apt update && sudo apt install dos2unix
3) Выполняем команду:
dos2unix script.sh
dos2unix: converting file script.sh to Unix format...
4) После выполнения данной команды, пытаемся запустить на скрипт script.sh
и проверить работоспособность.
I know there are some similar questions in here, but I want to know how did this occur. The Terminal started displaying this after I deleted a folder named root in my home directory, but I assumed that I was only deleting something unnecessary(also I was not asked for authentication). How can I go back to the way everything was before 🙁 ?
bash: config.sh: No such file or directory
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
source /home/trotteville/root/bin/thisroot.sh
./home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm
which is giving me a
bash: ./home/abcdef/Desktop/jikesrvm/dist/production_x86_64-linux/rvm: No such file or directory
rvm
is a bash file, and it does run ok when I attempt to run it from its own folder (production_x86_64-linux
). It works also fine if I attempt to run it when opening the terminal in its parent folder, for instance, or even its parent-parent folder.
I’ve run it over with dos2unix
just in case and I’ve also checked its executing permissions, which seem to be fine.
What am I missing here?
asked Apr 20, 2015 at 0:41
bash <location of the script file>
in your case
bash /home/abcdef/Desktop/jikesrvm/dist/production_x86_64-linux/rvm
it will work
what basically the . means is your current directory location.
./Desktop/jikesrvm/dist/production_x86_64-linux/rvm
chmod +x ~/Desktop/jikesrvm/dist/production_x86_64-linux/rvm
answered Apr 20, 2015 at 0:47
While you are trying:
./home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm
shell will always treat .
in front of a path as current directory and hence the path will always be a relative path. So, shell is trying to find an executable file in the location:
$PWD/home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm
which is wrong as you can see. You would run a executable script that is the current directory as ./script.sh
.
You can actually simply run the executable by using the absolute path (given the script is executable):
/home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm
Or as ~
is expaneded by shell as $HOME
:
~/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm
Or even just the name of the script if the directory containing the script is in the PATH
environment variable.
Now if your script is Not executable, you can run it too without making it an executable by telling the shell which program will handle the script i.e. giving the script as an argument to bash
(shell):
bash /home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm
answered Apr 20, 2015 at 1:28
20 gold badges198 silver badges264 bronze badges
When you use ./
to execute a file, it will look in the current folder (.
) for a folder named home
instead of starting from the root (/
) directory.
Using the bash
command explicitly like in bolzano’s answer starts from the root directory instead of the one you’re in.
To use the command without bash
you could enter
/home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm
Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm
from your home directory assuming it is marked executable.
answered Apr 20, 2015 at 0:55
16 silver badges28 bronze badges
answered Nov 18, 2019 at 17:55
-
cstad
- Posts: 7
- Joined: 2018-10-03 18:02
Boot failing: No init found
by cstad » 2018-10-03 18:28
Hi, my stretch install is failing to boot and I’m not sure how to interpret the logs:
Code: Select all
JBD2: Unrecognised features on journal
EXT4-fs (sda6): error loading journal
mount: mounting /dev/sda6 on /root failed: Invalid argument
done.
Begin: Running /scripts/local-bottom ... done
Begin: Running /scripts/init-bottom ... mount: mounting /dev on /root/dev failed: No such file or directory
mount: mounting /dev on /root/dev failed: No such file or directory
done.
mount: mounting /run on /root/run failed: No such file or directory
run-init: current directory on the same filesystem as the root: error 0
Target filesystem doesn't have requested /sbin/init.
run-init: current directory on the same filesystem as the root: error 0
run-init: current directory on the same filesystem as the root: error 0
run-init: current directory on the same filesystem as the root: error 0
run-init: current directory on the same filesystem as the root: error 0
run-init: current directory on the same filesystem as the root: error 0
No init found. Try passing init= bootarg.
And then it gives me an «(initramfs)» prompt. I tried running «fsck /dev/sda6» from there but it says it is clean.
I don’t have a good understanding of the boot process, and I’m scared of losing data, so any help or suggestions would be very deeply appreciated. Thank you.
-
p.H
- Global Moderator
- Posts: 3049
- Joined: 2017-09-17 07:12
- Has thanked: 5 times
- Been thanked: 130 times
Re: Boot failing: No init found
by p.H » 2018-10-03 19:32
You’re looking to the wrong direction. No init found is just a consequence of the failure to mount the root filesystem (which contains init). The important information is :
Code: Select all
JBD2: Unrecognised features on journal
EXT4-fs (sda6): error loading journal
Did you try fsck with -f ?
-
cstad
- Posts: 7
- Joined: 2018-10-03 18:02
Re: Boot failing: No init found
by cstad » 2018-10-03 20:41
Thanks, very useful to know that is the root problem. I ran «fsck -f /dev/sda6» but it didn’t find anything to fix. I found this article which had the same journal issue, but fsck fixed it for them.
-
cstad
- Posts: 7
- Joined: 2018-10-03 18:02
Re: Boot failing: No init found
by cstad » 2018-10-03 21:45
The /etc/fstab on initramfs is empty. How do I read the «real» fstab?
bw123 wrote:
why would you want to mount a volume on /root anyway?
I don’t know, where would it normally be mounted? There’s an env var «rootmnt=/root», is that related?
-
bw123
- Posts: 3980
- Joined: 2011-05-09 06:02
- Has thanked: 1 time
- Been thanked: 17 times
Re: Boot failing: No init found
by bw123 » 2018-10-03 23:59
You might need to explain a little better how your system got into this. It’s possible nobody here will know for sure what you did based on the error message alone, or how to fix it.
Did you change anything in the grub config? Did you alter the settings for initramfs somehow?
Since you said you’re scared to lose any data, I’m sure you have a backup made of anything important? If not, that would be the first thing to do. From a live system probably would be the best way.
resigned by AI ChatGPT
-
cstad
- Posts: 7
- Joined: 2018-10-03 18:02
Re: Boot failing: No init found
by cstad » 2018-10-04 00:22
That makes sense, and I really appreciate the help. I did not intentionally change anything before this happened. The only thing out of the ordinary was that I was installing virtualbox, so I will try to remember exactly what I ran while doing that. Yes, I need to backup some things first though.
-
p.H
- Global Moderator
- Posts: 3049
- Joined: 2017-09-17 07:12
- Has thanked: 5 times
- Been thanked: 130 times
Re: Boot failing: No init found
by p.H » 2018-10-04 07:44
bw123 wrote:why would you want to mount a volume on /root anyway? what’s in fstab?
The error happens during execution of the initramfs, before the final root filesystem is mounted. The main purpose of the initramfs is to mount the final root filesystem (which seems to be in /dev/sda6). It tries to mount it on /root, then switches to it as the new /. There is no fstab yet as it is in the root filesystem. The initramfs gets the root filesystem specification from the root= parameter in the kernel command line passed by the boot loader.
I once encountered «unrecognized features» errors when trying to mount an ext4 filesystem created with Stretch’s mke2fs default options on a Wheezy system with a 3.2 kernel. But IIRC they were not related to the journal but to some other new features such as metadata checksumming.
-
cstad
- Posts: 7
- Joined: 2018-10-03 18:02
Re: Boot failing: No init found
by cstad » 2018-10-04 13:34
Thanks p.H, any suggestions for how to figure out what the «unrecognised features» are?
I was able to use a live USB to backup my important data and pull some information which will hopefully be useful.
It sounds like this is probably not the issue, but here is /etc/fstab:
Code: Select all
# / was on /dev/sda6 during installation
UUID=3eda7621-8a70-4c32-96e2-049fb3d8102f / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/sda1 during installation
UUID=E02A-F4E4 /boot/efi vfat umask=0077 0 1
# swap was on /dev/sda7 during installation
UUID=29762f86-b82a-472c-ae0a-66f0521b29ec none swap sw 0 0
/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
And here is what I ran before rebooting:
Code: Select all
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
sudo apt update
sudo apt install virtualbox-5.2
sudo apt install ./vagrant_2.1.5_x86_64.deb
vagrant box add [...]
vagrant init [...]
vagrant up
VBoxManage --version
./etc/init.d/vboxdrv setup
sudo /etc/init.d/vboxdrv setup
sudo apt-get install dkms build-essential linux-headers-`uname -r`
sudo /sbin/vboxconfig
sudo rcvboxdrv setup
dpkg-reconfigure virtualbox-dkms
modprobe vboxdrv
-
p.H
- Global Moderator
- Posts: 3049
- Joined: 2017-09-17 07:12
- Has thanked: 5 times
- Been thanked: 130 times
Re: Boot failing: No init found
by p.H » 2018-10-05 07:31
cstad wrote:any suggestions for how to figure out what the «unrecognised features» are?
You can try
However there should not be any «normal» unrecognized features if the filesystem was created with the same version of Debian which is installed on it, and has been running fine until now. So I suspect some metadata corruption.
Now you have backed up the data, you could try to remove and re-create the journal with
Code: Select all
tune2fs -O ^has_journal /dev/sda6
tune2fs -O has_journal /dev/sda6
-
cstad
- Posts: 7
- Joined: 2018-10-03 18:02
Re: Boot failing: No init found
by cstad » 2018-10-05 20:33
I tried re-creating the journal and that did get me farther then before, but then there were a ton of messages like this:
Code: Select all
EXT4-fs warning (device sda6): dx_probe:472: Corrupt dir inode 7602194, running e2fsck is recommended.
EXT4-fs warning (device sda6): dx_probe:398: dx entry: limit != root limit
I then got a terminal from which I can log in, but no GUI, and running anything triggered more of the above error messages. fsck still says it’s clean though.
Unless there are any more suggestions I’m planning on re-installing. Thanks again!
-
debiman
- Posts: 3063
- Joined: 2013-03-12 07:18
Re: Boot failing: No init found
by debiman » 2018-10-06 11:45
cstad wrote:And here is what I ran before rebooting:
Code: Select all
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - sudo apt update sudo apt install virtualbox-5.2 sudo apt install ./vagrant_2.1.5_x86_64.deb vagrant box add [...] vagrant init [...] vagrant up VBoxManage --version ./etc/init.d/vboxdrv setup sudo /etc/init.d/vboxdrv setup sudo apt-get install dkms build-essential linux-headers-`uname -r` sudo /sbin/vboxconfig sudo rcvboxdrv setup dpkg-reconfigure virtualbox-dkms modprobe vboxdrv
crap, is this the proper way to install & set up virtualbox on debian?
to me it looks either outdated or way too low-level.
where did you get this from?
the virtualbox wiki does not have anything below apt install virtualbox-5.2.
-
cstad
- Posts: 7
- Joined: 2018-10-03 18:02
Re: Boot failing: No init found
by cstad » 2018-10-06 18:49
p.H wrote:Did you try again running fsck with -f while the filesystem was not mounted ?
Yes, from Debian on a live USB I ran «sudo fsck -f /dev/sda6» and it didn’t report any issues.
debiman wrote:crap, is this the proper way to install & set up virtualbox on debian?
Basically after the apt install it wasn’t working so I then started googling and running things from stackoverflow. Maybe not the best strategy. The virtualbox manual does say you may need to install linux kernel headers and then run «rcvboxdrv setup» (https://www.virtualbox.org/manual/ch02.html#idm936), but I’m not sure exactly why I ran the other things.
Хочу установить анаконду
для этого мне нужно запустить скрипт в командной строке
перехожу в командной строке в директорию где лежит скрипт
и прописываю его
выдвает ошибку No such file or directory
Почему так проичсходит.
root@w:/home/ut/Downloads# bash ~/Downloads/Anaconda3-2018.12-Linux-x86_64
bash: /root/Downloads/Anaconda3-2018.12-Linux-x86_64: No such file or directory
-
Вопрос заданболее двух лет назад
Почему так проичсходит.
Потому что такого файла нет. Есть такой, к примеру: Anaconda3-2020.11-Linux-x86_64.sh
, с .sh
в качестве расширения.
И устанавливать надо не от рута, а обычным пользователем.
Надо всегда обязательно читать, что написано в сообщении об ошибке.
Желательно — глазами.
Оно пишет человеческим языком — где мы сидим и какой файл пытаемся открыть
/home/ut/Downloads
/root/Downloads/
Не наводит ни на какие мысли?
А что у нас означает буквочка ~?
Ну и совсем уж риторический вопрос: раз уж мы перешли в папку с файлом, то зачем указывать путь к ней?
Ну и напоследок — не зря все мудрые руководства рекомендуют не сидеть под рутом
В Linux символ ~ используется для сокращенного обозначения домашней директории пользователя.
Вы сидите под пользователем root.
Дальше включите пожалуйста логику и посмотрите на вашу ошибку.
04 июл. 2023, в 09:01
15000 руб./за проект
04 июл. 2023, в 08:54
4000 руб./за проект
04 июл. 2023, в 08:43
1500 руб./за проект