Linux command no such file or directory

Basic commands not working i.e: -bash: ls: No such file or directory

I’m new to Unix and in the process of installing a program for my dissertation I must have played with the PATH for the basic Unix commands such as ls . Every time I type ls and the directory name I want to list the files for, it comes up as:

-bash: ls: No such file or directory 

4 Answers 4

Reset your path right now (i.e. before any sort of logout) with:

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 

It doesn’t get your full PATH restored but basic utilities will be available again.

Here’s an example of the sort of thing that happens:

You had a PATH variable (referred to as $PATH when reading from it)

$ echo $PATH /home/durrantm/.rvm/gems/ruby-2.0.0-p247/bin:/home/durrantm/.rvm/gems/ruby-2.0.0-p247@global/bin:/home/durrantm/.rvm/rubies/ruby-2.0.0-p247/bin:/home/durrantm/.rvm/bin:/h ome/durrantm/.autojump/bin:/usr/local/heroku/bin:/home/durrantm/bin:/home/durrantm/.autojump/bin:/usr/local/heroku/bin:/home/durrantm/.autojump/bin:/usr/local/heroku/bin: /home/durrantm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/durrantm/.rvm/bin:/home/durrantm/.rvm/bin:/home/durrantm /.rvm/bin 

You tried to add to it, but you accidentally used

and the result was that your path became

and then all the utilities like ls and sed don’t work

You can fix the minimal set by doing

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 

which is particularly useful if a login dot files is messing up your PATH
Check your .bashrc and/or .bash_profile files for any PATH changes.

As Greg says you can also just log out (or safer option, open a new window in case opening a new window is broken!) and then echo $PATH from a new window.

The same thing happens when you do path= with no values. It ‘wipes out’ your current path and causes these problems.strong text

As for why, when you have these problems cd works and ls doesn’t work:

  • cd is a «built-in» command that doesn’t need your PATH to find the program
  • ls is a program and need to use PATH to find where it is.
$ builtin ls -bash: builtin: ls: not a shell builtin 14:47:29 mdurrant C02MH2DQFD58 /Users/mdurrant $ builtin cd 14:47:31 mdurrant C02MH2DQFD58 /Users/mdurrant $ 

No error means the command is a builtin

Before ‘moving on’ (or logging out).

Make sure to test any changes (particularly those to .bashrc, .profile, etc that are doing PATH setting commands) by opening a new window or doing source ~/.bash_profile to run it. It’s also a good practice to keep the window and editor (when you are changing the .bash_profile file) open in case your changes don’t work and prevent you from opening new windows to edit the file. Though you can still use TextEdit or another simple editor to change the file (avoiding command line and vi for example). Be careful NOT to reboot if/when your shell is broken or you may not even be able to login. and that is really really bad (without another account to su from you are hosed). Has happened to me!

Читайте также:  Change permissions other users linux

My ‘extra account’ fix was also a life saver then though and highly recommended for all (do it now!)

Hey! Thanks a lot! I just reset the path, but when I open a new terminal window the same thing happens. I then did more ~/.bash_profile to check for any changes and it shows this: export PATH=

Make sure to test any changes by opening a new window or doing source ~/.bash_profile to run it. It’s also a good practice to keep the window and editor (where you are changing the .bash_profile file) open in case your changed don’t work and prevent you from opening new windows to edit the file. Though you can still use TextEdit or another simple editor to change the file.

The changes you’ve made to PATH are likely temporary. Close the shell you’re in with exit and reopen it.

In the event that you have edited a file that sets the PATH for newly opened shells, specify the full path to commands to fix whatever you’ve changed (eg. /usr/bin/vim ).

Hello! Thanks (: I tried doing this but it doesn’t work. I’m guessing I really did do something weird. I remember using vim to do something with PATH and then everything just got messed up. Ugh, wish I knew more computer language to get this thing sorted!

However, I only can see this or use any command when I input PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin this in a new terminal window..otherwise I cannot use any of the commands. It’s not recognising them :S

This answer is for those who logged out after editing the .bash_profile , which means you’re probably in a situation where you can’t use your login screen.

I can’t ensure you this will work for you.

Short Answer

If, for some reason, you don’t even have access to a shell, switch to a virtual console with Ctrl + Alt + F2 and login. Once you’re at a shell prompt, use command -p to edit the file in question, where is something like nano .bash_profile .

Long Answer

I’m using Manjaro, but I doubt that means anything in this scenario.

I was in the login screen. I typed my credentials and then nothing happened. As nothing was working anymore, I had no prompt to work with. I could move my cursor just fine, but none of the login screen buttons worked.

I pressed Ctrl + Alt + F2 . I now had a console terminal to work with. I could go back to the previous screen with Ctrl + Alt + F1 , but that wasn’t necessary.

I was met with a login prompt and filled in my credentials.

I tried using the commands am used to working with, but nothing worked. I’d get the default:

-bash: something_something: command not found. 

But, I found that I COULD use cd , but I couldn’t list directory contents with ls . I did some research and found out that cd is a built-in command. I wanted to confirm that I could work with built-in commands and found a way to display all of them:

Читайте также:  Oracle java x64 linux

I was now met with a lot of commands I could work with. I had no idea what most of them do. I could recognize commands such as source , cd , echo and exit . I couldn’t find any good material explaining how to use these built-in commands. Maybe I just didn’t search well enough. Anyway, since help is also a built-in command, I tried using it on some of the built-in commands. Eventually I did:

    Use a default value for PATH that is guaranteed to find all of the default utilities.

That sounded pretty useful, so I went ahead and tried to do:

And it worked. Now I figured that I just needed to edit the .bash_profile file and so I did:

cd ~ command -p nano .bash_profile 

I then deleted the few lines I had added that had messed up my path. If you don’t know which lines that is, then I suppose you’d be safe with some sort of default path. I can imagine that’s a thing. If it wasn’t .bash_profile that caused the issue for you, then I suppose you can try editing the file that did.

I then rebooted the system and everything was back to normal.

Источник

Solve No Such File or Directory Error in Linux Bash

Solve No Such File or Directory Error in Linux Bash

  1. Check Path and Interpreter to Solve the bash: No such file or directory Error in Linux Bash
  2. Install Library Packages to Solve the bash: No such file or directory Error in Linux Bash
  3. Use the dos2unix Command to Solve the bash: No such file or directory Error in Linux Bash

Linux terminal allows you to execute programs. This article will explain how to execute files properly and solve the bash: No such file or directory error in Linux Bash.

There are many code-related reasons why you get a bash: No such file or directory error in Bash. We will explain the most common mistakes and ways to fix them.

Check Path and Interpreter to Solve the bash: No such file or directory Error in Linux Bash

First, make sure you execute the program with the correct path. If you make a typo on the directory or file name, you will get this error or give the wrong path.

If you are executing the file with a relative path ( ../../file ), try executing with the absolute path ( /path/to/file ) instead.

Another reason you might get this error could be that you are using the wrong interpreter. The first line in the code is called shebang ( #!/bin/bash ).

It tells the operating system which shell to use to parse the file. If the shebang is not specified correctly, your program will not run.

Make sure the program uses the proper interpreter.

Install Library Packages to Solve the bash: No such file or directory Error in Linux Bash

Missing libraries on your system can cause you to get the bash: No such file or directory error. Examine the file with the file command.

If the file is a 32-bit executable, you need some libraries to execute it on a 64-bit architecture OS. To solve this error in Ubuntu, add the i386 architecture with the dpkg command, then install the necessary libraries.

sudo dpkg --add-architecture i386 sudo apt-get update sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 

Use the dos2unix Command to Solve the bash: No such file or directory Error in Linux Bash

Unix operating systems use line feed ( «\n» ) as the end of the line, but Windows operating systems use carriage return and line feed ( «\r\n» ). So if you try to execute a code written in Windows on Linux, you may get this error.

Читайте также:  Серверы времени ntp linux

You must clear the carriage return characters to be able to execute the file.

The dos2unix command-line tool is a DOS to Unix text file format converter and vice versa. You can use the dos2unix tool to make your file Unix compatible.

The file will be converted to Unix format. You can now execute the file.

While we have explained the most common errors and solutions here, this error can have many code-related causes. You can solve this by choosing the solution that suits your application.

Yahya Irmak has experience in full stack technologies such as Java, Spring Boot, JavaScript, CSS, HTML.

Related Article — Bash Error

Copyright © 2023. All right reserved

Источник

«No such file or directory» but it’s there.

As you can see from the above I’m trying to go to the folder brian2 but Ubuntu tells me No such file or directory but the directory list command tells me it is there.

2 Answers 2

From home to enter brian2 from /home/ , type in terminal

When to say cd /brian2 , it tries to navigate the folder at / but there is no folder brian2

Further Clarification as you asked in your comment

Christian Mann aptly said it, tilde ~ refers the same thing as /home/brian2 in your case.

~ refers to home for any user. For example,

For brian ~ refers to /home/brian

For brian1 ~ refers to /home/brian1 so on.

If brian1 enters to brian’s home (have to have permission) he will see at prompt

In Linux always you can modify things. There is a special shell variable PS1 which can modify the shell prompt in different ways as you wish.

Just to clarify, the point is that / refers to the very top of the hierarchy of your system. home is a top-level directory under / so /home refers to the home directory at the top of the hierarchy and /home/brian2 refers to the brian2 directory inside the home directory, whereas /brian2 refers to the non-existent brian2 directory at the top of the hierarchy. cd can also check the current directory, so if you are in /home already, it will go to /home/brian2 if you type cd brian2 . cd /home/brian2 does the same thing.

I would have thought it would have brought me to . brian2@ubuntu:/home/brian2$ ?? Thanks for your patience! Brian

@brian If this answer has answered your question please accept it to help keep our site clean and orderly. Thanks!

Источник

Оцените статью
Adblock
detector