2

I'm using VMWare, and running debian and whenever I run a new terminal my commands like "ls" seem to be lost.

I've tried the solutions listed here for instance: https://apple.stackexchange.com/questions/22859/bash-ls-command-not-found

When I do:

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

it works temporarily.

When I do:

cd ~
nano .bash_profile
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$PATH

-- the file changes and the save reflects but when I open a new terminal the commands are forgotten again.

Edit:

rowen@debianRhys:~$ echo $PATH 
/home/rowen/bin:PATH

source .bash_profile bash: dircolors: command not found

Rhys
  • 21
  • 1
    By "When I do...", you mean you follow the actual instructions of the answer, is this correct? Because the part you quoted here is not the same as the answer. If you did follow those instructions, it may be that the profile file is not ".bash_profile" but possibly ".bashrc". Or even ".profile" if your shell is not actually bash. – LSerni Feb 24 '21 at 08:07
  • Yes, I follow the instructions, putting that line of code into .bash_profile with nano and then saving it. It says bash: ls: command not found, so I figure it is bash. So should I try edit all of those files with that line? – Rhys Feb 24 '21 at 08:13
  • 1
    Open a new terminal and run echo "$PATH". Run source .bash_profile and check again. Edit your question and add the output. Also try to add it to .bashrc instead. – pLumo Feb 24 '21 at 10:27
  • I tried as you said, editing .bashrc. I added the line to the top of the code. There's actually code in this file though as opposed to the '.bash_profile'.

    I noticed it has these 3 lines at the bottom: 'PATH=~/bin:PATH PATH=~/bin:PATH PATH=~/bin:PATH'

    – Rhys Feb 25 '21 at 11:40
  • It is clear from your update that you have added the word PATH at the end of the shell's search path. This is likely due to a forgotten $. Double check your .bash_profile file. In a previous comment, you mention PATH=~/bin:PATH (etc.). This should definitely be PATH=~/bin:$PATH. – Kusalananda Feb 25 '21 at 11:44
  • Ah thank you! You are a life saver. Thank you to everyone for all your help. – Rhys Feb 25 '21 at 11:49

1 Answers1

2

From comments it was made clear that the user had one or several lines in their ~/.bash_profile file saying

PATH=~/bin:PATH

This would clear the PATH variable, resetting it to a list of paths that are not generally useful.

This would easily be remedied ty prefixing PATH with $ in the value assigned to the PATH variable:

PATH=~/bin:$PATH

This prepends ~/bin to the value of $PATH, rather than discarding the old value completely.

Kusalananda
  • 333,661
  • I had added PATH=xyz/... in my .env file and wondered why I could not use ls right after running source .env. Clearly because I destroyed my PATH variable, and it was back as soon as I reopened my shell. ;) – questionto42 Mar 07 '22 at 21:42