One of the most common questions asked by new Linux or Unix system users. When you get the error “Command not found,” it means that Linux or UNIX searched for command everywhere it knew to look and could not find a program by that name. Another cause is that you misspelled the command name (typo) or the sysadmin administrator does not install the command on your Linux/UNIX based system. To get rid of this error, try the following suggestions:
Make sure command was not misspelled
All Linux and UNIX commands are case sensitive, and you need to type the correct spelling of the command.
Make sure command is your path
PATH is an environment shell variable that shows the different directories that your shell will see in order to find commands. You can see the current search path with the following echo command/printf command:
$ echo "$PATH"
$ printf "%s\n" "$PATH"
Usually, all user commands are in /bin and /usr/bin or /usr/local/bin directories. All your programs are installed in these directories. When you type the clear command, you are running /usr/bin/clear. So if it is not in your PATH, try to add directories to your search path as follows (setup Linux or UNIX search path with following bash export command):
$ export PATH=$PATH:/bin:/usr/local/bin
You can also find out of the path using which command or whereis command or type command/command as follows:
$ which ls
$ which gcc
$ which date
$ which cal
$ whereis gcc
$ type -a gcc
gcc is /usr/bin/gcc
gcc is /bin/gcc
$ type -a time
Here is how it looks:
time is a shell keyword time is /usr/bin/time time is /bin/time
$ command -V time
time is a shell keyword
Typing full path
You can run a program using its full pathname. For instance, run ls as /bin/ls:
$ /bin/ls $ /bin/date
Finally, sometimes you may not have permission to run the command. Remember, all Unix or Linux commands or scripts must have executable permission set. We can verify (view file permission) this using the ls command:
$ ls -l /bin/ls
$ ls -l ~/bin/toc
Outputs indicating my custom script called ~/bin/tochel has executable permission for user, group, and others:
-rwxrwxr-x 1 vivek vivek 132 Oct 19 00:31 /home/vivek/bin/toc
We can display file information and status easily by using the stat command:
$ stat /bin/ls
macOS Unix desktop or Linux desktop file manager also displays file permission. Make sure you have executable permission:
Of course, we can use the chmod command to set executable permission:
$ chmod +x filename
$ chmod +x /path/to/filename
## sysadmin level permission needed for other users ##
$ sudo chmod +x /path/to/file.sh
Run the command as the root / superuser
Some commands need privileged access. Hence run it as follows:
sudo -u userName command2
See “How do I become superuser on Ubuntu Linux using su/sudo?” and “How Can I Log In As root User?” for more info.
The curious case of missing command
If a typed Unix command is not in PATH and anywhere on the system means the command or app is not installed at all. Hence, the last option is to install a missing package.
You think your command is installed on Linux or Unix/macOS desktop. Still, you or the sysadmin/vendor didn’t install the Unix command to begin with. Here is an example when I type bashtop:
And system will say:
bash: bashtop: command not found
In other words, bashtop may not be installed, and we need to install the same. For instance I can install bashtop using the operating system’s package manager:
$ snap install bashtop # snaps (apps) on Linux
$ sudo apt install bashtop # Debian Linux
$ sudo dnf install bashtop # Fedora Linux
$ sudo pacman -S bashtop # Arch Linux
Now we can run the command that was missing:
Let’s assume the program you want to execute is called “cal,” and you get a “Command not found” error message from Unix or Linux system. First, type the following command to see if you get a pathname:
$ whereis cal
cal: /usr/bin/cal /usr/share/man/man1/cal.1.gz
If you do, you can invoke it using a full path name (e.g. /usr/bin/cal):
September 2012 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Or you can add the path to your PATH variable in your shell start-up file $HOME/.cshrc (csh/tcsh) or $HOME/.bashrc (bash) file, then “source” the file:
$ vi $HOME/.bashrc
Add the path as follows:
PATH=$PATH:/home/vivek/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games export PATH
Save and close the file. Run the following source command:
$ source ~/.bashrc
$ echo "$PATH"
Finally, you can use the following find command to search for cal command get a hit about its location.
$ find / -name cal -print
Another faster option is to use the locate command:
$ locate cal
Then, invoke it using a full path name or add it to your PATH variable in your shell startup file.
In short, look for the following to fix “bash: bashtop: command not found“:
- Make sure the shell PATH variable correctly set and verify your PATH environment variable.
- Verify that the file you want to execute or run exists on the Unix or Linux box.
- Some commands need to run as the superuser (root user). Typically we use sudo or su.
- Ensure the software package is installed for missing command, and you have permission to run the command.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
|Category||List of Unix and Linux commands|
|Firewall||Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|