Меню

Ошибка bash command not found

I have written a bash script that gets three paths based on input parameters and then then gets the imagename/filename in the path.

Something like:
I provide:

AA=/home/user

Then it uses the find command to get
/home/user/dir2/images/dir/tellmeimage1fun.bin

Finally I have to get tellmeimage1fun.bin as output.

Script:

#!/bin/bash  

echo "arg0 n/k/d"  

AA=$1  
CC=$3  

PATH1="`find $AA/dir2/images/dir/ -name *image1*.bin`"  
PATH2="`find $AA/dir2/images/dir/ -name *bimage2*.bin`"  
PATH3="`find $AA/dir2/images/dir/ -name *cimage3*.bin`"  

if [ $CC = "n" ] ; then  
    PATH=$PATH1  
elif [ $CC = "k" ] ; then  
    PATH=$PATH2  
else  
    PATH=$PATH3  
fi  

#Getting filename name from path:  
IMG="`ls $PATH | cut -d "/" -f6`"

OUTPUT:  
/users/prasapat/bin/sl5: line 22: ls: command not found  
/users/prasapat/bin/sl5: line 22: cut: command not found  

If I give complete paths to ls and cut they work. But i don’t want to do that for all commands in the script. If i remove the last line and echo the PATH variable it is completely fine. Only after adding the last command, I see the problem.

What am I doing wrongly?

codeforester's user avatar

codeforester

37.2k16 gold badges107 silver badges132 bronze badges

asked Apr 12, 2011 at 22:48

Pkp's user avatar

The problem is that you are redefining the PATH variable where bash looks into to find the binary files if you don’t use a complete path when calling.

You should change the PATH in your bash script to MYPATH or something like that, so that it doesn’t mess with the already environmental variables.

If you don’t know what the PATH variable is for you can look at wikipedia’s article

answered Apr 12, 2011 at 22:56

Santiago Alessandri's user avatar

1

I had this problem, turns out editing a bash script using Notepad++ was adding DOS line endings instead of UNIX line endings. Running the script in a Linux environment was causing the ‘command not found’ error to be thrown.

Managed to diagnose the problem by running my script like so:

bash -x testscript.sh

Which will dump any compiler output. The error message that gets thrown is:

bash -x testscript.sh
+ $'r'
: command not found 2:
'estscript.sh: line 3: syntax error near unexpected token `{

I fixed the issue by changing the formatting of line endings in Notepad++ to be UNIX not DOS by going Edit -> EOL Conversion -> UNIX.

answered Oct 18, 2017 at 11:07

Tom Walsh's user avatar

1

$PATH is a special environment variable that contains a list of directories where your shell (in this case, bash) should look in when you type a command (such as find and ls.) Just try echo $PATH in a script or in a shell to get a feeling of what it looks like (you will typically have /bin, /usr/bin and /usr/local/bin listed there, maybe more.)

As you don’t really need to redefine this variable in this particular script, you should use another name than $PATH.

codeforester's user avatar

codeforester

37.2k16 gold badges107 silver badges132 bronze badges

answered Apr 12, 2011 at 23:03

Frederic De Groef's user avatar

$PATH is a predefined variable which gives the directories to search when looking for executables. Pick a different variable name for your script and you’ll be fine.

answered Apr 12, 2011 at 22:56

John Kugelman's user avatar

John KugelmanJohn Kugelman

342k67 gold badges517 silver badges565 bronze badges

Use a different variable name than PATH. $PATH is the environment variable which tells your shell where to look for executables (so, e.g., you can run ls instead of /bin/ls).

answered Apr 12, 2011 at 22:56

entropo's user avatar

entropoentropo

2,45115 silver badges15 bronze badges

You are using the PATH that is special and used to locate the commands and that is why ls can’t be resolved. Use any name other than PATH

if [ $CC = "n" ] ; then  
    MY_PATH=$PATH1  
elif [ $CC = "k" ] ; then  
    MY_PATH=$PATH2  
else  
    MY_PATH=$PATH3  
fi 

export MY_PATH

IMG="`ls $MY_PATH | cut -d "/" -f6`"

answered Apr 12, 2011 at 22:57

amit_g's user avatar

amit_gamit_g

30.5k8 gold badges60 silver badges118 bronze badges

The command not found error is one of the most common errors in Linux. The cause of the occurrence of this error is the system’s inability to find the file which you have mentioned in your path variable.

What is a path variable?

The path variable will tell our Linux system about the places to look for certain files or commands. The path variable generally contains paths such as /usr/local/sbin, /usr/bin, /usr/local/bin, etc. Normally we do not specify the path variable each time, because it is pre-configured to look for programs in all the directories.

Now that we know a little bit about the path variable let us see how we can resolve the command not found error.

Different ways to fix this error:

1. Installing the package which is not present:

Sometimes when we write a command in Linux, the system is unable to find it because it is simply not present on our system. For example, we will try to run python which is not installed in our system

You can see the command not found error, to resolve this simply install python. 

sudo apt-get install python

Now when you will type python, the error will be gone.

2. Explicitly telling bash where to look:

Sometimes, especially for scripts, we do not have to rely on the path we just execute them right away, so that they are executed wherever they are. We do this by putting “./” in front of them. We have created a script named GFG, let us execute it.

 ./GFG.sh

But if we do not include the “./” before the script name then it gives us the command not found error. Let us see this from an example. We will create another script “Sample.sh” and try to execute it.

You can see that it is giving us the same error, we will resolve it in the next step.

3. Modifying the path variable:

Understanding Environment variables

These are the variables that are necessary to set up the environment of a Linux shell. These reside in the child process of the shell variables. These are of two types local and global. The standard convention for writing an environment is to write it in capital letters preceded by a “$” symbol. For example, the $PATH variable. In layman’s terms with the help of these variables, we can modify the way in which the applications work on our system.

Let us understand the PATH environment variable:

With the help of this variable, we can specify the directory whenever we need to find a command. The default value of this variable is stored in the /etc/profile file. We do not type the entire path of the command every time, that is because the $PATH variable is configured in such a way that it tells the system where to look for that command.

For us, to be able to run the “Sample.sh” script simply by writing it we are going to add it to the Path variable. Let us first see all the Paths. Use the below command to see the path:

echo $PATH

We are currently in the /home/mukul directory and it is not recommended to add the home directory to the path. So we will create a bin folder(which will contain the Sample.sh script) and concatenate it to the path variable. Type the below commands to create a bin folder and move the Sample.sh into it.

mkdir bin
mv Sample.sh bin/Sample.sh

Adding a directory to the PATH variable

By default there are a lot of different directories which are present in this variable, we can also add our own directory into the PATH variable which will enable us to run our script or command from anywhere in the system. This definitely saves a lot of time and effort. There are two ways in which we can add to PATH:

  1. By appending (This adds our path at the end of the PATH variable)
  2. By prepending( This adds our path at the beginning of the PATH variable)

Now we have to attach the /home/mukul/bin to the path, use the below command:

export PATH = $PATH: /home/mukul/bin (appending)

export PATH =  /home/mukul/bin :$PATH (prepending)

You can see that our path has been added to the path variable.

Now we can run our “Sample.sh” script from anywhere and that too without any path or “./” mentions.

Note: Make sure to give permission to your file, or else it will give an error.

chmod +x Sample.sh

4. You have misspelled the command:

We all make mistakes and that is a natural thing, this error can also arise when we type the command incorrectly.

For example, If we type PQD instead of PWD we will get this error.

So these were the four ways in which you can get rid of the  Bash: Command Not Found Error in Linux.

When you’re trying to run a command (with or without sudo) and get an error message that reads «Command not found,» this means the script or file you’re trying to execute doesn’t exist in the location specified by your PATH variable. What is this variable, and how can you run commands that it can’t find?

Understanding environment variables

In computing, a variable is a placeholder for a value that can change. You use variables every day in normal speech, although you don’t think of them as such. When you say «my laptop,» you’re using «laptop» as a generic variable or placeholder for the computer you’re carrying, regardless of whether it happens to be a Lenovo, Mac, or a Raspberry Pi in a fancy case.

Environment variables are special variables that contain information about your login session. Many of these variables are set by default during installation or user creation. They’re stored for the system shell, applications, and scripts to use when executing commands.

There are global, or system-defined, variables and local, or user-defined, variables.

Global variables

Global variables come predefined in your login shell, but they aren’t immutable and can be modified or deleted according to your preferences. You can use the printenv or env commands to display the environment variables on your system:

$ env 
SHELL=/bin/bash 
SESSION_MANAGER=local/kiwi.homelinux.local:@/tmp/.ICE-unix/1906,unix/kiwi.homelinux.local:/tmp/.ICE-unix/19
06 
WINDOWID=153092103 
COLORTERM=truecolor 
XDG_CONFIG_DIRS=/home/tux/.config/kdedefaults:/etc/xdg:/etc/kde/xdg 
LESS=-XR 
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1 
HISTCONTROL=:ignorespace:ignoredups:ignorespace:ignoredups 
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/share/pkgconfig:/usr/lib64/pkgconfig:/usr/share/pkgconfig 
[...]

The env command prints out all global environment variables. Variables are case sensitive, and all Linux distributions use uppercase for environment variable names by default.

[ Keep your favorite Git commands, aliases, and tips close at hand. Download the Git cheat sheet. ]

Local variables

A local variable exists only within a specific shell. Therefore, when you define a local variable, it’s only available in your current shell. It doesn’t propagate or persist to a new shell session unless you export it as a global variable.

Local variables are often defined in lowercase to avoid overwriting a global variable with the same name.

The PATH environment variable

The PATH global environment variable lists the directories your system searches for valid, executable commands. By default, it contains standard directories that normally store executables like /usr/bin, /usr/local/bin, and so on.

When you type in a command, such as grep or vim, your system searches through all directories listed in your PATH variable, in the order that they’re listed, until it finds an executable file by the same name. Should it fail to find one, it issues the «Command not found» error.

$ printenv PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/tux/.local/bin:/home/tux/bin

$ env $PATH
env: /usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/tux/.local/bin:/home/tux/bin

5 ways to fix «Command not found» errors

There are several ways to fix this problem. Here are five of them.

1. Include the path

Not everything you want to execute needs to be in your path. You can execute files directly by specifying the path to the file you want to run. By identifying the file’s location, you circumvent the need for your system to search your path at all.

For example, suppose you have a script called hello that you want to run. It’s located in your home directory, and you have already marked it as executable with chmod +x:

$ ~/hello
hello world

By telling your system the file’s location, the PATH variable is never involved, and the file runs as expected.

2. Add a new path

Alternately, you can add a new directory to your PATH. Add your executable files to that directory, and then you can run them without manually providing a path:

$ cp ~/hello ~/.local/bin
$ export PATH=$PATH:$HOME/.local/bin
$ printenv PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/tux/.local/bin

You may want to add the new PATH environment variables to your login shell by including them in your .bashrc file as new settings.

3. Copy a file to an existing path location

If you want to execute your binary file or script, copy it to any of the directory paths already listed in the PATH environment variable:

$ sudo cp ~/hello /usr/local/bin/
$ hello
hello world

4. Tell Bash where to look

Probably the simplest option, especially for one-off scripts or applications, is to tell Bash not to consider the PATH but rather to «look here.» Do this by placing a dot and a slash in front of the command, script, or application name. For the hello script, it looks like this:

$ sudo ./hello
hello world

No permanent changes are made to the system. This might be handy if you’re writing a script and want to test it before copying or moving it to its normal storage location (presumably along the PATH).

5. Install a package

Sometimes when you try to use a command and Bash displays the «Command not found» error, it might be because the program is not installed on your system. Correct this by installing a software package containing the command. For example, if you don’t have Nmap installed, then the nmap command fails when you type it into a terminal:

$ nmap
nmap: command not found
$ sudo dnf install --assumeyes --quiet nmap
$ nmap
Nmap 7.92 ( https://nmap.org ) 
Usage: nmap [Scan Type(s)] [Options] {target specification}
[...]

[ Want to learn more? Sign up for a free trial of full access to Red Hat’s curriculum. ]

Stick to the path

The PATH variable is a powerful tool you can use to customize how your system responds to commands, so take some time to get comfortable with it. It’s frequently used when running commands to find the command executable.

In this tutorial, you learned five ways to fix a «Command not found» error in your terminal—three of which rely on the PATH variable. Now that you know what variables are and how command executables are found, you won’t be so mystified when the «Command not found» error appears on your screen.

Are you using Linux and you have seen the “Command Not Found” error while trying to execute a command? It’s time to find out why.

We will look at this error together and understand how to fix it.

What is the cause of the command not found error?

The “Command not found” error is caused by the fact that Linux is unable to find on your system a command you try to execute. When you run a command Linux looks for binaries in the list of directories specified in the PATH environment variable, this allows you to execute a command without specifying its full path.

In this article we will go through an example of this error and I will show you how to fix it.

You will also understand how Linux (or Unix-like systems) look for commands when a user executes them.

Let’s start!

The PATH Environment Variable

Linux system are configured with a pre-defined set of environment variables required by the operating system to function properly.

The PATH environment variable is one of the most important environment variables in a Linux system. It contains a list of directories used by Linux to search for commands that can be executed without specifying their full path.

You can use the echo command to see the value of the PATH variable:

[ec2-user@localhost ~]$ echo $PATH
/home/ec2-user/.local/bin:/home/ec2-user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

In the list of directories inside the PATH you can see the home directory for my current user (ec2-user) but also directories like /usr/bin.

Let’s have a look at some of the commands present in the /usr/bin directory. To restrict the list of commands returned by ls, I just look for commands starting with ch (I use the ch* wildcard to do that):

[ec2-user@localhost]$ ls -al /usr/bin/ch*
-rwxr-xr-x. 1 root root  17488 May 11  2019 /usr/bin/chacl
-rwsr-xr-x. 1 root root 133928 Nov  8  2019 /usr/bin/chage
-rwxr-xr-x. 1 root root  19216 Nov  8  2019 /usr/bin/chattr
-rwxr-xr-x. 1 root root 150528 Apr  9 18:53 /usr/bin/chcon
-rwxr-xr-x. 1 root root 140232 Apr  9 18:53 /usr/bin/chgrp
-rwxr-xr-x. 1 root root  61920 Nov  8  2019 /usr/bin/chmem
-rwxr-xr-x. 1 root root 133952 Apr  9 18:53 /usr/bin/chmod
-rwxr-xr-x. 1 root root 146360 Apr  9 18:53 /usr/bin/chown
-rwxr-xr-x. 1 root root  47816 Nov  8  2019 /usr/bin/chrt
-rwxr-xr-x. 1 root root  14272 May 11  2019 /usr/bin/chvt

Let’s take the chmod command as an example.

If I use the which command to check the full path of the chmod command I get the following:

[ec2-user@localhost]$ which chmod
/usr/bin/chmod

As you can see this is exactly the same directory in the PATH, /usr/bin.

The fact that /usr/bin/ is in the PATH allows us to execute the chmod command withouth having to specify its full path.

Makes sense?

Where Is PATH Defined in Linux?

Wondering where is the PATH environment variable defined?

Let’s find out…

It’s usually defined somewhere in your home directory, and specifically in one of the hidden files used in Linux to configure your user environment: the .bashrc file.

In Linux, the dot before the name of a file means that the file is hidden. It’s not visible if we execute the ls command without flags. It’s only visible if you pass the -a flag to the ls command.

The .bashrc file is actually a shell script that gets executed when Linux initialises an interactive shell. This allows you to configure your environment the way you want every time you open your shell.

If I look at the .bashrc file on my system I see the following lines:

# User specific environment
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
export PATH

As you can see the PATH variable is defined and it’s then made available to any child processes of this shell using the export command.

If you want to add another directory to the PATH you can simply update the .bashrc file.

This is a common requirement if you download external tools that are not part of the Linux operating system and you want to be able to execute them from your shell without having to specify their full path.

One common scenario is adding Java to the Linux PATH after downloading the JDK (Java Development Kit) on your system.

PATH Configured At System-Wide Level

When I see the value of the PATH variable on my system, here’s what I get:

/home/ec2-user/.local/bin:/home/ec2-user/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

There’s something that doesn’t make sense to me…

…in the .bashrc file in the home directory on my user I only see:

PATH="$HOME/.local/bin:$HOME/bin:$PATH"

So, where do the following directories come from considering that they are not in my user’s .bashrc file?

/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

They must be defined somewhere at system level and not just at user level.

In Linux, system-wide configuration files are located under the /etc directory. For example in /etc/bashrc.

Let’s find out where this initial value for the PATH comes from using a recursive grep as root under the /etc directory.

[root@localhost]$ grep -r PATH /etc/* | grep "/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
/etc/ssh/sshd_config:# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

The only result is in the configuration file for the SSH deamon. According to a comment in this file, the daemon is compiled with the PATH set to the value I’m seeing on my system.

That’s where the value of the PATH comes from!

How Do I fix the Bash error “command not found”?

So far we have seen what the PATH is…

…but how does it help us fix the command not found error?

First of all, before looking at how the command not found error could be related to the PATH, let’s look at a simple cause.

Before doing any other checks make sure you are not misspelling the command when you execute it.

This might be happening mostly to those who are new to Linux and are learning the commands.

If the way you have typed the command is correct, then keep going…

The next reason could be that the directory where the command is located is not in the PATH and there could be two reasons for that:

  1. The command is available on the system but its directory is not in the PATH.
  2. The command is not available on the system at all.

Scenario 1 can occur if you download a specific tool on your Linux system and you don’t add the directory in which the binary is located to the PATH environment variable.

To update the value of the PATH you have to modify the .bashrc file.

Let’s say the current value of the PATH is:

PATH="$HOME/.local/bin:$HOME/bin:$PATH"

And I want to add the directory /opt/install to it because that’s where the command I want to execute is located. That line would become:

PATH="$HOME/.local/bin:$HOME/bin:$PATH:/opt/install"

The order of the directories in the PATH is important, the first directory has higher priority than the second directory, and so on.

So, if you want the /opt/install directory to be the first one to be searched when a command is executed the PATH definition becomes:

PATH="/opt/install:$HOME/.local/bin:$HOME/bin:$PATH"

Notice the dollar $ in front of PATH. This is REALLY important because it refers to the existing value of the variable PATH.

Omitting the $ sign in this line could have catastrophic effects on your system. That’s because the shell wouldn’t know anymore where to find basic commands like ls, cd, vim, etc…

In the next section we will look at the scenario 2, where the command is not available on your Linux system.

Running a Command Not Available on the System

Now, let’s have a look at what happens when we execute a command that is not available on a Linux system.

I take, for example, the rsync command:

[ec2-user@localhost ~]$ rsync
-bash: rsync: command not found

How do I know if I’m seeing the “command not found” error because the rsync command is not in the PATH or because it doesn’t exist on the system at all?

I can use the package manager of my Linux distribution. In this case I’m using CentOS and hence I will use the yum command to see if the rsync package is installed:

yum list --installed | grep rsync

This command doesn’t return any results, this means rsync is not available on the system.

Another option is to use the RPM command to query the RPMs installed on my Linux system:

rpm -qa | grep rsync

Once again, no results for the rsync package.

So, let’s install it!

The yum search command returns a result for rsync:

[ec2-user@localhost ~]$ yum search rsync
Last metadata expiration check: 1 day, 4:15:26 ago on Sun 19 Jul 2020 05:12:46 PM UTC.
=================================== Name Exactly Matched: rsync ===================================
rsync.x86_64 : A program for synchronizing files over a network

And we can install the rsync package using the “yum install” command:

[ec2-user@localhost ~]$ sudo yum install rsync
......
....

Installed:
  rsync-3.1.3-7.el8.x86_64

Complete!

And now if I try to execute the rsync command again to check its version:

[ec2-user@localhost ~]$ rsync --version
rsync  version 3.1.3  protocol version 31
Copyright (C) 1996-2018 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/

The command works well!

Conclusion

In this guide we have seen three possible scenarios in which the “command not found” error can occur on Linux when we execute a command:

  1. We have misspelled the command.
  2. The command is available on the system but its directory is not in the PATH.
  3. The command is not available on the system.

I have also explained how the PATH environment variable works and how important is for a Linux system.

Have you managed to find what’s causing this error in your system?

Let me know in the comments below! 🙂

Related posts:

I’m a Tech Lead, Software Engineer and Programming Coach. I want to help you in your journey to become a Super Developer!

I was updating my .bash_profile, and unfortunetly I made a few updates and now I am getting:

env: bash: No such file or directory
env: bash: No such file or directory
env: bash: No such file or directory
env: bash: No such file or directory
env: bash: No such file or directory
-bash: tar: command not found
-bash: grep: command not found
-bash: cat: command not found
-bash: find: command not found
-bash: dirname: command not found
-bash: /preexec.sh.lib: No such file or directory
-bash: preexec_install: command not found
-bash: sed: command not found
-bash: git: command not found

My bash_profile actually pulls in other .sh files (sources them) so I am not exactly sure which modification may have caused this.

Now if I even try and to a list of files, I get:

>ls
-bash: ls: command not found
-bash: sed: command not found
-bash: git: command not found

Any tips on how to trace the source of the error, and how to be able to use the terminal for basic things like listing files etc?

Jjed's user avatar

Jjed

13.5k10 gold badges63 silver badges91 bronze badges

asked Sep 12, 2012 at 2:08

Blankman's user avatar

5

It looks to me that at one point or another you are overwriting the default PATH environment variable. The type of errors you have, indicates that PATH does not contain /bin, where the above commands (including bash) reside.

For example, if you do

PATH=/home/user/bin

instead of

PATH="$PATH":/home/user/bin

heemayl's user avatar

heemayl

88.8k19 gold badges195 silver badges262 bronze badges

answered Sep 12, 2012 at 2:34

January's user avatar

JanuaryJanuary

34.5k14 gold badges81 silver badges100 bronze badges

10

One way to begin debugging your bash script would be to start a subshell with the -x option:

$ bash --login -x

This will show you every command, and its arguments, which is executed when starting that shell.

The —login option is specified because .bash_profile is read by login shells. Further information on debugging bash scripts can be found here: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html.

Ultimately, I think that January’s suggestion will work for you, but that link is worth a read for future problems.

answered Sep 12, 2012 at 3:23

K. P. MacGregor's user avatar

K. P. MacGregorK. P. MacGregor

1,1761 gold badge9 silver badges9 bronze badges

2

I may have found the problem. It worked for me, and it might work for you…

I was defaulting with my editor to Windows (LF/CR) saves. Since I use both systems, it seemed logical. When I needed to mess with my .bash_profile, I realized after commenting out and tryig things that nothing worked. I changed my saves to OS X format (CR only) and voilà! No more «command not found» in the terminal!

It may just be that easy!

overcomer's user avatar

answered Jan 7, 2014 at 22:14

cyphire's user avatar

cyphirecyphire

1311 silver badge2 bronze badges

3

After I couldn’t re-run . ~/.bash_profile or any usual commands like whoami, grep, etc.
I figured a way to just re-export the required paths:

export PATH=/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/cpanel/composer/bin:/usr/local/easy/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin

This should work in most systems, although some of these paths are not present in all Linux packages. It worked for me.

answered Oct 3, 2016 at 19:06

Ananth's user avatar

AnanthAnanth

1611 silver badge2 bronze badges

I think I may have found the answer to the problem if not for you then for others who have a similar problem. My answer to this is that I do not have a .bash_profile.

So I was searching all over the web and I found the solution. Which is basically open the terminal, type touch ~/.bash_profile and press Enter. That fixed my problems. Hope it does the same for you

Waldir Leoncio's user avatar

answered Apr 30, 2014 at 15:28

Paul's user avatar

PaulPaul

412 bronze badges

1

I have the same problem like you. I can’t use many popular command (ls, vi/vim, ..) and can’t edit /root/.bashrc when I log in with su into root.

Finally. I found the solution for this problem. Just login root with command:

su -m

After that, you can use

vim /root/.bashrc

to edit PATH.

Goodluck!

NorTicUs's user avatar

NorTicUs

2,3522 gold badges18 silver badges34 bronze badges

answered Nov 8, 2012 at 7:40

MrReS's user avatar

MrReSMrReS

211 bronze badge

I had the same problem. You may have missed a $ while exporting PATH. You should open the .bash_profile in TextEdit. If you can’t find the file in the directory, press Command + Shift + > to show hidden files.

Then make correction to the PATH and then save.

In the directory on Terminal, type: source .bash_profile.

This should resolve the issue.

answered Aug 6, 2016 at 3:04

Kensam's user avatar

1

I had exactly the same problem:

If I put in lxterminal:

set | grep "jerom/bash"
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jerom/bash/

if I entered exactly the same command in tty2 I got:

set | grep "jerom/bash"
PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jerom/bashr

r means DOS end of line, so I opened file ~/.bashrc and change the ends of lines in Krusader to unix style. And its working already!!! 🙂

The DOS EOLs make spourious problems also in bash scripts.

Eric Carvalho's user avatar

Eric Carvalho

53k102 gold badges134 silver badges161 bronze badges

answered Mar 31, 2014 at 0:27

xerostomus's user avatar

xerostomusxerostomus

7397 silver badges17 bronze badges

I got the same problem just now after I changed the .bash_profile.
And I want to change it back but now I can’t, because I lost all the commands, especially the nano command and the vim command, so I can’t open the .bash_profile with command. And the .bash_profile is a hidden file I can’t open it with the Finder.

So I need to find a way to open the .bash_profile file.
After I tried many ways I found that I can use Atom, because Atom can read all files in a project folder, include the hidden files.
So just open Atom, and select the File -> Open, choose <yourusername> folder, and then, all hidden files is showing on the Atom’s tree view, include the .bash_profile!!
After I removed the last modification and reopen the Terminal, all commands came back! 🙂

muru's user avatar

muru

188k50 gold badges459 silver badges709 bronze badges

answered Feb 6, 2017 at 3:57

backslash112's user avatar

When you type a command in the Linux Terminal, you expect an output. But sometimes you might encounter ‘Bash : Command Not Found’ error in the terminal. In this article, we will take a look at why this error occurs and how can we resolve this issue.

This error simply means that the command you entered is not recognized by the shell (bash) because either that command is not installed or you are typing the command that does not exist. This could also be due to misspelled command. Let’s check how we can fix this error.

Method 1. Check The Spelling

You might have made a spelling mistake while typing the commands. Even I sometimes become confused between I (Capital i) and l (Small L) and 1 (numeric 1). Make sure that you have entered the correct command name and that you have used the spaces and options in the command correctly. For example, here I have typed the wrong command, and therefore I have encountered the error.

Type The Correct Command
Type The Correct Command

Method 2. When the Command is not installed

Maybe the command you are trying to use is not installed on your distribution. In that case, install the command using your appropriate package managers such as apt, Pacman, DNF, or zypper. For example, I don’t have nano installed on my system because I use the Vim text editor. But if I try to open my .bashrc file using nano, I will receive the mentioned error.

Make Sure That Package Is Installed
Make Sure That Package Is Installed

Method 3. When the command in use is an Alias

We often store our commands in the bashrc file in the form of an alias so that we do not have to type long commands often. But this can create problems for you, especially when you log in to the same computer using another user ID or when you access any other computer. In that case, try to find out the correct command for what you’re trying to achieve. You can also go back to your PC/User and type the following command to know all the aliases stored for you in the bashrc file:

Check Aliases For Your User
Check Aliases For Your User

Now you can copy-paste the actual commands in the Terminal.

Summary

There certainly isn’t one way to fix this problem, as there could be a number of reasons causing this problem in the first place. Hopefully, the above-mentioned methods were able to fix this error for you.

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Ошибка b2799 тойота королла 150
  • Ошибка base game not installed