Score:-1

Accidentally changed PATH variable and I cant change it back, or use vim etc..help

hn flag

I know there are many questions like this, but I unfortunately dont know enough about Ubuntu to be able to apply it to my situation. I have all my stuff saved for work on a remote machine, that i access via ssh. I was trying to change something with a conda environment i have there, and changed something in the .bashrc file, and now I cant use vim, or ls - no text editor or command seems to work.

echo $PATH returns: /home/percyrou/bin:/home/percyrou/bin:/home/user/bin:~/ghf_env/bin/

as far as i remember from the .bashrc file before i accidentally changed it, the PATH was just something like : /home/user/bin:

I think all these extra parts got added because i tried to change it with :

echo 'export PATH="/home/percyrou/bin:$PATH"' >> ~/.bashrc (or just with user instead of percyrou, because i wasnt sure which it was), and it seems to add it to the PATH rather than replace it. I did already run source ~/.bashrc

i also tried to use scp to download the .bashrc file to my local machin and edit there, but that also returns bash: scp: command not found, i guess because scp is also contained in my .bashrc file.

Please help! I have no idea how to proceed from here to access my path variable again. :(

mook765 avatar
cn flag
When your PATH is broken, use full path to executable like `/usr/bin/scp` instead of `scp`.
Mike avatar
rw flag
You could add /usr/bin to PATH so "scp", "ls", etc can be found. export PATH=/usr/bin:$PATH.
Cyrus avatar
cn flag
Your vim is there: `/usr/bin/vim`
Score:5
cn flag
raj

You are still able to use scp and other commands, only you need to type the absolute path like /usr/bin/scp instead of just scp (or similarly /usr/bin/ls instead of ls etc.) because the shell cannot find these commands on your $PATH.

Try /usr/bin/cat .bashrc to display the contents of your .bashrc file or /usr/bin/vim .bashrc to edit it. If you can't make the file work properly by editing it, there is a default .bashrc file (that is copied to each user's home directory when creating account) under /etc/skel/.bashrc. Use the following command to copy it over your current .bashrc file:

/usr/bin/cp /etc/skel/.bashrc .bashrc
Learn4life avatar
hn flag
Okay this is great thank you !Its still not working yet, but at least with ```/usr/bin/vim``` i can at least open it, thanks already so good to know!
Learn4life avatar
hn flag
Okay I copied over the default, and it still doesnt work. But since my question was mostly about how to access my stuff again, your answer was a success! Thanks so much :)
raj avatar
cn flag
raj
Did you log in again to a new session after copying the default? It's strange that the default file doesn't work... What is your `$PATH` after logging in to a new session with default `.bashrc` file?
Score:0
cn flag

Reset your path to a minimum usable version

PATH=$(getconf PATH)

Then fix your .bashrc

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.