Technical Anshu
Tutorials Blog

This is one of the most reported self-caused Linux breaks on Unix and Linux Stack Exchange, and the pattern is always the same: a line meant to extend PATH replaced it instead. A line like PATH=/home/user/bin on its own tells the shell to look in only that one folder, so /usr/bin and /bin - where ls, sudo, nano and almost every normal command live - are never searched again. Nothing is deleted and nothing needs reinstalling. You only need to give the current terminal a working PATH, then correct the one bad line in the startup file so new terminals start clean.

Terminal  .  bash
Every command says command not found.
bash: ls: command not found bash: sudo: command not found

X Commands that worked an hour ago - ls, sudo, cp, nano - all fail the same way in a new terminal

X The break started right after editing ~/.bashrc or ~/.profile to add a folder to PATH

PATH BROKEN  The shell is only searching the wrong folder list. The programs themselves are untouched.

The fingerprint of this problem: it starts right after a .bashrc or .profile edit, and it hits basic commands, not just one program.

1

Restore a Working PATH for This Session ⭐

Do this first, in the same broken terminal. It does not edit any file - it only repairs PATH for the terminal that is already open, so your normal commands work again while you fix the real cause in the next steps.

  1. Type this line exactly and press Enter: export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  2. Test it straight away with ls and which ls. The second command should print a normal path such as /usr/bin/ls.
  3. If a tool is still needed before this export has run, call it by its full path - for example /usr/bin/nano ~/.bashrc. The full path works because it does not rely on PATH at all.
  4. Do not close this terminal until Fix 2 is done. A new terminal reads the still-broken startup file and will be broken again.
2

Fix the Bad Line in .bashrc and .profile

The permanent fix is in the file you edited. Bash reads ~/.bashrc for interactive terminals, and ~/.profile is read at login and is also where PATH lines are often added. Check both - the bad line only has to exist in one of them.

  1. Open the first file with nano ~/.bashrc - PATH is restored now, so the short name works. Use /usr/bin/nano ~/.bashrc if it does not.
  2. Find every line that sets PATH. The broken pattern is a line that assigns PATH without keeping the old value, for example PATH=/home/$USER/bin or export PATH=/opt/some-folder on its own.
  3. Correct it so the old PATH is kept and your folder is only added. The correct pattern from the verified fix is: export PATH="$PATH:/home/$USER/bin" - note the $PATH at the start, which is the part that was missing.
  4. Delete or correct any other line that replaced PATH entirely, then save with Ctrl+O, Enter, and exit with Ctrl+X.
  5. Repeat the same check in ~/.profile. If the same bad line is there, fix it the same way. Zsh users should check ~/.zshrc instead of .bashrc - the same overwrite mistake breaks zsh in the same way.
3

Check /etc/environment if Every Account Is Affected

If only your own account is broken, the cause is in your home folder files above and this step can be skipped. If every user on the machine gets command not found, the system-wide PATH file may have been edited instead.

  1. Open the system file with sudo nano /etc/environment once PATH is restored in your session. This file holds a single PATH line for the whole system on Ubuntu and Debian family systems.
  2. A healthy line lists the standard folders, for example PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin". If the line here was replaced with a single custom folder, restore the standard folders and only append your custom folder at the end.
  3. Save the file and log out and back in - /etc/environment is read at login, not by terminals that are already open.
  4. Do not edit other files under /etc to chase this problem. For a single-user break, .bashrc and .profile are the files that matter, and /etc/environment is the only system file worth checking.
4

Verify in a Brand New Terminal

The fix only counts if a fresh terminal - one that reads the corrected startup files from scratch - works. Testing in the repaired terminal alone proves nothing, because that terminal still holds the temporary export from Fix 1.

  1. Close all terminal windows completely, then open a new terminal.
  2. Run echo $PATH and confirm the list contains /usr/bin and /bin, plus your custom folder at the end if you added one.
  3. Run which ls and which sudo. Both should print a full path instead of returning nothing.
  4. Run a few normal commands, starting with a plain ls directory listing. If listings, file commands and one sudo command all respond normally, the shell is healthy again.
5

Software Needed

No extra software is needed. Everything in this guide uses tools that are already on the system - the bash shell itself, a text editor such as nano called by its full path when needed, and the built-in echo and which commands for verification. Do not reinstall the distribution or reinstall core packages for this problem: no package is missing, and a reinstall would discard your settings to fix a single text line that takes a minute to correct by hand.

Remember the rule for next time: always extend PATH, never replace it. Every custom PATH line should start with $PATH, like export PATH="$PATH:/new/folder". If a guide or script tells you to set PATH to one folder alone, it is written for a container or a special shell, not for your daily terminal - following it on a normal desktop breaks every basic command in new terminals.
What NOT to do: do not delete ~/.bashrc or ~/.profile to fix this - you would lose your aliases and settings to remove one bad line. Do not copy a stranger's whole .bashrc file over yours either; startup files differ between Ubuntu, Fedora and Arch. Correct only the PATH lines, keep the rest of your own file, and verify in a new terminal.

More Linux Fixes on Technical Anshu

Every week: Linux, Windows and server problems, hidden tools and full setup guides, explained step by step.

Subscribe on YouTube

Frequently Asked Questions

Why does ls say command not found when ls is still installed?

Because the shell finds commands by searching the folders listed in PATH, and a broken PATH no longer includes /usr/bin or /bin where ls lives. The program file is still on disk - the shell simply never looks in the folder that contains it. Restoring PATH with the export command in this guide makes the same installed commands work again without reinstalling anything.

Will restarting the PC fix a broken PATH?

No. Restarting does not repair the startup file. Every new login and every new terminal reads ~/.bashrc or ~/.profile again, so the same bad line breaks PATH again after every restart. The restart only helps after you have corrected the line - then a fresh terminal or a fresh login picks up the corrected value.

What is the correct way to add a folder to PATH?

Append to the existing value instead of replacing it. The correct pattern is export PATH="$PATH:/home/$USER/bin" - the $PATH part keeps all the standard system folders, and your folder is added at the end. Put that line in ~/.bashrc for bash terminals, check ~/.profile as well if the line was added there, and open a new terminal to test it.

Sudo also says command not found. How can I edit files as admin?

In the broken session you do not need sudo to fix your own files - ~/.bashrc and ~/.profile belong to your account. First restore PATH for the session with export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin, after which sudo works normally again. Before that export, any tool can still be run by its full path, for example /usr/bin/nano ~/.bashrc.

Does this fix work the same on Fedora and Arch, or only on Ubuntu?

Yes, the same fix works on Ubuntu, Debian, Fedora and Arch, because all of them use bash the same way: a PATH line that overwrites instead of appending breaks command lookup, and the export command restores the standard folders for the session. The only difference is the startup file name for other shells - zsh users should check ~/.zshrc instead of ~/.bashrc.

Guide by Technical Anshu · Problem collected from real user reports on Unix and Linux Stack Exchange - "Every command says command not found after editing .bashrc / PATH"; solution written in original words and checked against that thread's verified restore route (session export, then correcting the appending PATH line in .bashrc and .profile, with /etc/environment checked for system-wide cases) and standard bash startup behaviour on Ubuntu, Debian, Fedora and Arch. No video exists yet for this problem on the channel, so this topic is saved as a fresh video topic. No Shorts are linked in this blog.