bash: /usr/bin/command: No such file or directory — fix
Your shell can't find a command you typed. Usually happens after a bad PATH edit or a package removal that broke a symlink.
You type ls, sudo, or even bash itself, and the shell spits back:
bash: /usr/bin/command: No such file or directory
Or maybe just:
command not found
This usually shows up right after you edited your .bashrc or .profile and messed up the PATH variable. Another common trigger: you ran apt-get remove or yum remove on something you thought was just a library, but it pulled out a critical command like sudo or bash itself. I’ve also seen this happen when someone deleted /usr/bin or /usr/local/bin by accident — yes, that’s a real thing people do.
What’s actually happening
The shell can’t find the executable. It looks through every directory listed in your PATH variable, one by one, in order. If the command isn’t in any of those directories, or if PATH itself is empty or set to a wrong location, you get that error. The real issue is almost always one of three things:
- Your
PATHenvironment variable is broken. - The command was uninstalled (or accidentally deleted).
- The binary itself is missing or corrupted — less common, but possible.
The fix — step by step
We’ll start with the quickest check, then move to deeper repairs. Do these in order. Don’t skip steps.
Step 1: Check your current PATH
Type this:
echo $PATH
You should see something like:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
If your output is blank or just one short directory like /home/you/bin, that’s your problem. The shell has nowhere to look for system commands.
Step 2: Fix a broken PATH right now (temporarily)
If you can still type commands at the shell (even if some don’t work), run this to set a safe, full PATH:
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Now try ls or sudo again. If it works, the fix is temporary — it’ll reset when you open a new terminal. But it gets you working now.
Step 3: Fix PATH permanently
Edit your shell’s startup file. For Bash, it’s ~/.bashrc or ~/.profile. For Zsh, it’s ~/.zshrc. Open it with a text editor:
nano ~/.bashrc
Look for a line that says export PATH=. If you see one that looks truncated or wrong, replace it with the line from Step 2. Then save (Ctrl+O, Enter, Ctrl+X). After that, reload the file:
source ~/.bashrc
Now test your commands again.
Step 4: What if you can’t even run nano or export?
This happens when PATH is so broken that even basic shell built-ins don’t work. In that case, you need to use the full path to a command. For example:
/usr/bin/nano ~/.bashrc
Or if /usr/bin is gone too, try /bin/nano or /usr/local/bin/nano. If none of those work, you’re in a tougher spot — see the next section.
Step 5: Reinstall the missing command
Let’s say you can get a shell but sudo still says “not found”. That means sudo was uninstalled. Install it back using your package manager with the full path to the package manager itself:
- Debian/Ubuntu:
/usr/bin/apt-get install --reinstall sudo - RHEL/CentOS:
/usr/bin/yum reinstall sudo - Arch:
/usr/bin/pacman -S sudo
If the package manager itself is missing (ouch), you’ll need to boot from a live USB, mount your root partition, and chroot in. That’s advanced territory, but the process is:
- Boot from a live Linux USB.
- Find your root partition (usually
/dev/sda1or/dev/nvme0n1p2). - Mount it:
mount /dev/sda1 /mnt - Chroot:
chroot /mnt - Now reinstall whatever is missing:
apt-get install --reinstall bash sudo(or whatever) - Exit and reboot.
What to check if it still fails
If you’ve done all the above and commands still don’t work, here’s what to look at next:
- Check if the binary exists at all. Run
ls -la /usr/bin/sudo(or the command you’re missing). If it’s not there, you need to install it — the package was removed, not just the PATH. - Check for broken symlinks. Sometimes
/usr/binis a symlink to something like/bin. If that link is broken, nothing in/usr/binworks. Runls -la /usr/binand look for a dangling arrow. Fix it withln -sf /bin /usr/binif needed. - Check your shell’s hash table. Bash caches command locations. If you moved or replaced a binary, the cache might be stale. Clear it with
hash -r. - Check for a corrupted
.bashrcor.profile. A syntax error in one of these files can prevent it from running at all, leaving you with no PATH. Rename them temporarily:mv ~/.bashrc ~/.bashrc.bak, then open a new terminal. If commands work now, that file had the problem.
The bottom line: 90% of the time, this is a broken PATH you can fix in 30 seconds. The other 10% is someone accidentally nuked a system package. Either way, the steps above will get you back to a working terminal.
Was this solution helpful?