Cause #1: The file isn't in your PATH
This is the big one. About nine times out of ten, when someone tells me "I just installed this tool and it says command not found," the binary is sitting in a directory that bash isn't looking in. Bash only searches the directories listed in your PATH environment variable. If the file isn't in one of those, it's invisible to the shell.
I had a client last month who downloaded a custom backup script to /opt/backup-tool, ran backup-tool and got bash: backup-tool: command not found. The file was right there, permissions were fine. He just never added that folder to his PATH.
How to check
First, confirm the file actually exists:
ls -l /opt/backup-tool/backup-tool
Then check your PATH:
echo $PATH
If the directory isn't listed, you have three options. The quick and dirty one: run it with the full path.
/opt/backup-tool/backup-tool
If you'll use it often, add the directory to your PATH. For just your user, edit ~/.bashrc (or ~/.zshrc if you're on zsh):
export PATH="$PATH:/opt/backup-tool"
Then reload:
source ~/.bashrc
For system-wide, put that line in /etc/profile or create a file in /etc/profile.d/. Don't mess with /etc/environment unless you really know what you're doing—I've seen that cause weird login loops.
The third option: symlink the binary into a directory already in your PATH, like /usr/local/bin. That's my go-to for single tools.
sudo ln -s /opt/backup-tool/backup-tool /usr/local/bin/backup-tool
Once you've done any of those, the command should work. If not, move on to cause #2.
Cause #2: The executable bit is missing
Here's the sneaky one. The file exists, it's in your PATH, but it's not marked as executable. When you try to run it by name, bash says command not found—even though it's literally right there. This happens all the time with scripts downloaded from the internet or copied from Windows.
I remember helping a user on Ubuntu who had downloaded a Python script from a repo, put it in ~/bin, and couldn't figure out why it wouldn't run. The fix took two seconds.
How to check and fix
Look at the permissions:
ls -l ~/bin/my-script
If you see something like -rw-r--r-- instead of -rwxr-xr-x, there's no executable bit. Add it:
chmod +x ~/bin/my-script
And that's it. Now bash will find it and run it. But wait—there's another layer. Even with the bit set, if the script's first line points to a missing interpreter, you'll get a different error. That's cause #3.
Cause #3: Broken or missing shebang line
Let's say you've verified the file is executable and in your PATH. You type myscript and still get command not found. The culprit is usually the shebang line—the first line of the script that tells the kernel which interpreter to use. If that interpreter doesn't exist, the kernel can't run the script, and bash reports it as not found.
Classic example: a script written on a system where Python is at /usr/bin/python3, but you're on a distro where it's at /usr/local/bin/python3 or only python exists. The shebang says #!/usr/bin/python3, that path is empty, and boom—command not found.
Another one I've seen: scripts with Windows line endings (CRLF). The shebang becomes #!/bin/bash
and the kernel looks for /bin/bash
which doesn't exist. This is super common when someone writes a script on Windows and transfers it to Linux.
How to check
View the first line:
head -1 myscript
Make sure it points to a real interpreter. Test it directly:
/usr/bin/python3 myscript
If that works, the shebang is wrong. Fix it with a proper path, or use #!/usr/bin/env python3 which searches PATH—more portable. For line endings, run:
sed -i 's/\r$//' myscript
Or use dos2unix if you have it. I keep dos2unix installed on every server I touch, because it's always the little things that bite.
Quick reference table
| Cause | Symptom | Fix |
|---|---|---|
| Not in PATH | Command not found, but full path works | Add directory to PATH or symlink |
| No executable bit | File exists, but can't run | chmod +x filename |
| Bad shebang | Script fails even with correct perms | Fix interpreter path or line endings |
These three cover almost every case I've run into. If you've checked all three and it's still failing, check that you're not in the wrong directory—I've done that more times than I'll admit. And if you're messing with a system command like ls or grep that suddenly says not found, your PATH is probably broken—log in with the full path like /bin/ls and fix your environment.