Limmor1

Q: sudo: command not found - damaged PATH file in terminal. How to restore?

Hi, I was editing one of the PATH variables holding file (~/.bash_profile or somewhere deeper), something went wrong and now terminal can't find any program (i.e. nano) or use sudo.

 

The problem is that to edit that file I need to be admin, but I can't use sudo. Any ideas?

Posted on Jul 19, 2014 6:51 AM

Close

Q: sudo: command not found - damaged PATH file in terminal. How to restore?

  • All replies
  • Helpful answers

  • by Linc Davis,Helpful

    Linc Davis Linc Davis Jul 19, 2014 10:42 AM in response to Limmor1
    Level 10 (207,990 points)
    Applications
    Jul 19, 2014 10:42 AM in response to Limmor1

    Back up all data.

      
    Select

      

              Shell ▹ New Command

      

    from the Terminal menu bar. Uncheck the box marked

      

              Run command inside a shell

      

    if checked.

        

    Copy and paste the following line into the text box that opens, then press return:

    mkdir disabled_shell_files

      
    Close the Terminal window that opens. Repeat with this line:

    mv .profile .bash_history .bash_profile .bashrc .inputrc disabled_shell_files

      

    Your old shell initialization and history files will be saved in a directory named "disabled_shell_files" at the top level of your home directory. It's normal that some of these files will not exist, and therefore you will get some "no such file" errors.

      

    Close the window, open a new one, and test.

  • by Limmor1,Solvedanswer

    Limmor1 Limmor1 Jul 21, 2014 5:11 AM in response to Linc Davis
    Level 1 (1 points)
    Jul 21, 2014 5:11 AM in response to Linc Davis

    Thank Linc,

     

    I have tried your suggestion and it pointed me to the right direction. The suggested method, however created no files in /disabled_shell_files, which meant I have my paths set up somewhere else (?). I didn't know you can run commands outside shell, which worked with sudo. So I checked my /etc/profile and found the faulty line. I was able to remove it with sudo nano /etc/profile and it fixed the problem!

     

    Thanks

  • by Limmor1,

    Limmor1 Limmor1 Jul 21, 2014 5:13 AM in response to Limmor1
    Level 1 (1 points)
    Jul 21, 2014 5:13 AM in response to Limmor1

    By the way, the faulty line was "export PATH=/opt/local/bin:/opt/local/sbin:/Users/limmor1/Coursera$PATH". It was probably because I didn't include a colon on adding the last path.

  • by BobHarris,

    BobHarris BobHarris Jul 21, 2014 6:00 AM in response to Limmor1
    Level 6 (19,479 points)
    Mac OS X
    Jul 21, 2014 6:00 AM in response to Limmor1

    It was probably because I didn't include a colon on adding the last path.

    Correct.

  • by ahlazcano,

    ahlazcano ahlazcano Sep 17, 2016 9:02 AM in response to Linc Davis
    Level 1 (4 points)
    Mac OS X
    Sep 17, 2016 9:02 AM in response to Linc Davis

    Thank you

    reply, it has also helped me