Disclosure: some links on this page are affiliate links. If you sign up through them we may earn a commission at no extra cost to you. It helps keep LinuxDistroFinder free.
You open a terminal, type a command you found online, and the shell fires back: bash: foo: command not found. Frustrating — especially when you have no idea why it worked for someone else and not for you. The good news is that the most common Linux terminal errors each have a short list of very predictable causes, and once you know the pattern you can diagnose and fix almost any of them in under two minutes.
This guide walks through the ten most frequently encountered Linux shell errors, explains exactly what each message means under the hood, and gives you concrete, copy-paste-ready fixes. We cover command not found, permission denied, no such file or directory, operation not permitted, and more — with real examples on Ubuntu, Debian, Fedora, and Arch.
1. "bash: command not found" (and "zsh: command not found")
This is the single most searched Linux error on the internet. It means the shell looked through every directory listed in your $PATH environment variable and could not find an executable with the name you typed. There are five common reasons this happens.
Reason 1: The package simply isn't installed
The most obvious cause. If you type htop and it isn't installed, the shell can't find it. Fix it by installing the package for your distro:
# Debian / Ubuntu / Linux Mint / Pop!_OS
sudo apt install htop
# Fedora / RHEL 9+ / AlmaLinux
sudo dnf install htop
# Arch Linux / Manjaro / EndeavourOS
sudo pacman -S htop
# openSUSE Tumbleweed / Leap
sudo zypper install htopcommand-not-found helper is installed by default on Ubuntu but may be absent on minimal installs. Reinstall it with sudo apt install command-not-found && sudo update-command-not-found.Reason 2: The binary isn't in your $PATH
Some programs install to non-standard locations like /usr/local/bin, ~/.local/bin, or /opt/something/bin. If that directory isn't in $PATH, the shell won't find the binary even though it physically exists on disk.
First, confirm the binary exists somewhere:
# Search common locations for a binary named "myapp"
which myapp # only searches $PATH
whereis myapp # broader search including man pages
find / -name myapp -type f 2>/dev/nullIf find locates it — say at /opt/myapp/bin/myapp — add that directory to your PATH permanently:
# Add to ~/.bashrc (bash users) or ~/.zshrc (zsh users)
echo 'export PATH="$PATH:/opt/myapp/bin"' >> ~/.bashrc
source ~/.bashrc~/.local/bin is the standard user-level binary directory per the XDG spec. Modern Ubuntu and Fedora add it to $PATH automatically if it exists — but only if it was present when your session started. If you created the directory mid-session, log out and back in.Reason 3: Typo or wrong case
Linux filenames are case-sensitive. Python ≠ python ≠ python3. On many modern distros the python symlink no longer exists — only python3 does. If scripts break, create the symlink yourself:
# Check what Python binaries exist
ls /usr/bin/python*
# Create a python → python3 symlink (Debian/Ubuntu)
sudo ln -s /usr/bin/python3 /usr/bin/pythonReason 4: Script not marked executable
If you wrote a shell script and try to run it as myscript.sh, the shell looks for a binary named exactly that in $PATH. You either need to call it as ./myscript.sh (explicit path) and make sure it has execute permission, or add its directory to $PATH.
# Mark the script executable
chmod +x myscript.sh
# Run it with an explicit path
./myscript.shReason 5: Alias or function only exists in another shell/session
If a command works in your interactive terminal but fails in a cron job or SSH session, it's likely defined as an alias in ~/.bashrc — which non-interactive shells don't source. Move the definition to ~/.bash_profile or use the full absolute path in the cron job.
2. "Permission denied"
You have the right command and it's installed, but you don't have the rights to run it or access the file it needs. There are two main sub-cases:
Running a command that requires root
# Wrong — runs as your user
apt update
# Right — runs with superuser privileges
sudo apt update
# If sudo isn't available (e.g. on some servers), use su
su -c "apt update"File/directory permission issue
Check the permissions on the file in question with ls -l. The output looks like -rwxr-xr--. The three groups of three characters represent owner, group, and others (everyone else). If your user is in the "others" bucket and only has r--, you can read but not write or execute.
# See file permissions and ownership
ls -l /path/to/file
# Give the owner execute permission
chmod u+x /path/to/file
# Give everyone read+write (use carefully)
chmod 666 /path/to/file
# Change ownership to your user
sudo chown $USER:$USER /path/to/filechmod 777 on system directories or web-facing files. It grants full read/write/execute to literally every user on the system, which is a serious security hole.3. "No such file or directory"
This one is almost always one of three things: a genuine typo in the path, a relative vs. absolute path confusion, or a broken symlink.
# Check if the path actually exists
ls -la /path/you/think/exists
# Check if a symlink is broken (points nowhere)
file /path/to/symlink
# Find where you actually are right now
pwd
# List hidden files too — maybe it starts with a dot
ls -la ~/A particularly sneaky variant: Windows-style line endings (\r\n) in a shell script copied from a Windows machine. The \r character gets appended to filenames and commands, making them unresolvable. Fix it with:
# Install dos2unix if needed, then convert
sudo apt install dos2unix
dos2unix myscript.sh4. "sudo: command not found"
On minimal Debian installs and many VPS images, sudo itself is not installed. You need to install it as root and add your user to the sudo group:
# Switch to root first
su -
# Install sudo
apt install sudo
# Add your user to the sudo group (replace "alice" with your username)
usermod -aG sudo alice
# Exit root shell, log out completely, log back in
exitwheel, not sudo. Use usermod -aG wheel alice instead.5. "Operation not permitted" vs. "Permission denied" — What's the difference?
Permission denied is a filesystem-level rejection — your user doesn't have the POSIX permissions for that file or directory. Operation not permitted (EPERM) is a kernel-level rejection — even root isn't allowed to do what you're trying to do, usually because of a security module like AppArmor, SELinux, or a container namespace restriction.
If you're running inside Docker or an LXC container and hit EPERM, the operation likely requires a Linux capability your container doesn't have. Check with:
# Show your current process capabilities
cat /proc/self/status | grep Cap
# Decode the hex value (replace XXXXXXXXXX with the value from above)
capsh --decode=XXXXXXXXXXQuick-Reference Error Table
| Error Message | Most Likely Cause | First Fix to Try |
|---|---|---|
command not found |
Package not installed or not in $PATH | Install the package with your distro's package manager |
Permission denied |
Missing file/exec permissions or need root | Prefix command with sudo or fix with chmod |
No such file or directory |
Typo in path, wrong working directory, broken symlink | Run pwd and ls -la to confirm location |
Operation not permitted |
Kernel/capability restriction, SELinux, AppArmor, container | Check security module logs: sudo dmesg | grep -i denied |
sudo: command not found |
sudo not installed (common on minimal/VPS installs) |
su - then apt install sudo |
Argument list too long |
Glob expands to more arguments than the kernel allows (~2 MB) | Use find ... | xargs instead of a bare glob |
Broken pipe |
The reading end of a pipe closed before writing finished | Usually harmless; suppress with 2>/dev/null |
command: line N: syntax error |
Script has a typo, missing quote, or Windows line endings | Run bash -n script.sh to check syntax without executing |
The Most Common Distro-Specific Gotchas
python vs python3
Very Common
Since Ubuntu 20.04 and Debian 11, the python binary is gone by default. Scripts that call #!/usr/bin/env python will fail. Fix: sudo apt install python-is-python3 — this package creates the symlink for you without any manual ln commands.
On Fedora and RHEL, SELinux can silently block commands that would work fine on Debian. If you're getting EPERM or an unexpected "Permission denied" even as root, check: sudo ausearch -m avc -ts recent. If SELinux is the culprit, use audit2allow to generate a policy fix rather than disabling SELinux entirely (which is a bad idea on production).
Commands like yay or paru aren't installed by default on Arch. If a guide says to run yay -S something and it fails with command not found, you need to install the AUR helper first manually via git clone and makepkg. See the Arch Wiki AUR helpers page for the official steps.
Apps installed as Snaps or Flatpaks run in a sandbox. Their binaries might not be exposed in $PATH at all, or they're exposed only as wrappers (e.g. /snap/bin/firefox). If you installed something via Snap and can't call it by name, check ls /snap/bin/ and ensure /snap/bin is in your $PATH.
Debugging a "Command Not Found" Systematically
When you're not sure where to start, use this checklist in order — it covers 99% of cases:
# Step 1: Confirm exact spelling with tab-completion or which
which node
type node
# Step 2: Print your PATH and look for obvious missing directories
echo $PATH
# Step 3: Search the filesystem for the binary
find /usr /opt /home/$USER -name "node" -type f 2>/dev/null
# Step 4: Check if it's installed as a package at all
dpkg -l | grep nodejs # Debian/Ubuntu
rpm -qa | grep nodejs # Fedora/RHEL
pacman -Q nodejs # Arch
# Step 5: See what package provides a given binary (even if not installed)
apt-file search bin/node # Debian/Ubuntu (needs: sudo apt install apt-file)
dnf provides /usr/bin/node # Fedora
pkgfile node # Arch (needs: sudo pacman -S pkgfile)Fixing PATH Permanently the Right Way
Many guides tell you to edit /etc/environment or /etc/profile — and while that works, it affects every user on the system. For single-user PATH changes, the correct approach depends on your shell:
# For bash — add to the END of ~/.bashrc
export PATH="$HOME/.local/bin:$PATH"
# For zsh — add to the END of ~/.zshrc
export PATH="$HOME/.local/bin:$PATH"
# Apply immediately without logging out
source ~/.bashrc # or: source ~/.zshrc
# Verify it took effect
echo $PATH$PATH (before $PATH) if you want them to take priority over system binaries. Put them at the end if you want system binaries to win. This matters when you have multiple versions of a tool — e.g. system Python vs. a pyenv-managed Python.Common Errors When Running Shell Scripts
"bash: ./script.sh: /bin/bash^M: bad interpreter"
The ^M is a Windows carriage-return character. The script was written on Windows. Fix it with dos2unix script.sh as shown earlier.
"syntax error near unexpected token 'fi'"
This almost always means a missing then, an unclosed quote, or a misspelled keyword somewhere above the reported line. Run bash -n script.sh to get a syntax check without executing anything — it's much safer than running a half-broken script.
"command not found" on line 1 of a script
Check your shebang line. It must be #!/bin/bash (or #!/usr/bin/env bash) — not # !/bin/bash with a space after the hash, and not #!/bin/bash with a trailing space (another Windows editor artifact).
Practice on a Real Linux VPS — No Risk to Your Main Machine
The fastest way to get comfortable with Linux errors is to break things freely on a disposable server. Vultr gives new users $100 in free credit — enough for weeks of hands-on practice on real hardware.
Claim $100 Free Credit on Vultr →Prefer managed hosting? Hostinger VPS starts at under $5/month and includes a clean Ubuntu or Debian image ready to go.
Frequently Asked Questions
Why does a command work for root but not for my regular user?
The most common reason is a $PATH difference. Root's PATH often includes /sbin and /usr/sbin, which regular users don't have by default. Commands like ifconfig, ip, and fdisk live there. You can still run them as a regular user with sudo /sbin/ifconfig using the full path, or add /sbin:/usr/sbin to your user's PATH.
I installed a program with pip but "command not found" still shows. Why?
Pip installs scripts to ~/.local/bin when run without sudo. That directory might not be in your $PATH. Run echo $PATH | grep local to check. If it's missing, add export PATH="$HOME/.local/bin:$PATH" to your ~/.bashrc and run source ~/.bashrc. Also note: if you ran pip with sudo, the script went to /usr/local/bin, which should already be in PATH.
What does "command not found" exit code 127 mean?
Exit code 127 is the POSIX standard exit status for "command not found." If you're scripting and need to detect this condition, check $? immediately after the command: if [ $? -eq 127 ]; then echo "not installed"; fi. This is useful for writing scripts that auto-install dependencies if they're missing.
The command works interactively but fails in a cron job — why?
Cron runs with a very minimal environment. It doesn't source ~/.bashrc or ~/.profile, and its default PATH is typically just /usr/bin:/bin. Solutions: use full absolute paths in your cron commands (e.g. /usr/local/bin/node instead of node), or set PATH explicitly at the top of your crontab with PATH=/usr/local/bin:/usr/bin:/bin.
How do I find which package provides a binary I don't have installed yet?
On Debian/Ubuntu: install apt-file (sudo apt install apt-file && sudo apt-file update), then run apt-file search bin/commandname. On Fedora: dnf provides /usr/bin/commandname works out of the box with no extra tools. On Arch: install pkgfile and run pkgfile commandname.
Is it safe to add /usr/local/sbin to my regular user's PATH?
Generally yes for personal machines — it just means you can type commands like sysctl without the full path. You'll still need sudo to actually run privileged operations. On shared or multi-user systems, be more cautious: a malicious binary placed in a writable directory early in PATH could shadow a system command.