Changed the PATH, now I'm getting "command not found" for everything

26

3

Amazon Linux Server, connected with SSH:

I tried to change the PATH for the apache user by making some changes in /etc/environment (PATH=$PATH:/opt/openoffice4/program) and /etc/sysconfig/httpd (export PATH = ${PATH:$PATH:}/opt/openoffice4/program).

Then I rebooted.

Now, I can not do anything, even ls -l leads to -bash: ls: command not found

What can I do to regain control?

Ferenjito

Posted 2015-11-13T10:01:56.827

Reputation: 363

4Can you run commands directly? For example /bin/ls? – DavidPostill – 2015-11-13T10:13:32.077

yes, I can run /bin/ls – Ferenjito – 2015-11-13T10:14:18.033

13Then you should be able to run /bin/vi and fix the files where you broke the path. – DavidPostill – 2015-11-13T10:15:54.257

Answers

49

What can I do to regain control?

Run /bin/vi and revert the changes you made to /etc/environment and /etc/sysconfig/httpd .

DavidPostill

Posted 2015-11-13T10:01:56.827

Reputation: 118 938

32

You can set your PATH without an editor. Just type this in the shell:

export PATH=/usr/local/bin:/usr/bin:/bin:$HOME/bin

Tom Zych

Posted 2015-11-13T10:01:56.827

Reputation: 921

1And remove the spaces! PATH=something, NOT PATH = something – waltinator – 2015-11-13T21:46:14.817

4That ought to be quoted, or else $HOME will be subject to globbing and word-splitting. IOW, it will break if $HOME has a space in it (plausible) or any glob characters (less likely). – Kevin – 2015-11-13T22:22:34.900

@Kevin I tried it and the spaces and globs were just copied. (Writing export PATH=/path to home/bin doesn't work, of course.) – Neil – 2015-11-14T01:34:32.470

2@Kevin That's how it behaves in strictly conforming implementations, but at least bash gives export custom syntax rules which don't have that problem. (Custom syntax rules were already required for other reasons, e.g. to allow export array=(1 2 3).) – hvd – 2015-11-14T09:29:00.683

-1

Maybe this would help:

export PATH=/usr/local/bin:/usr/bin:/bin:$HOME/bin

The 'export' command isn't used from /usr/bin, so that's why it still works!

Felix Weber

Posted 2015-11-13T10:01:56.827

Reputation: 1

1This answer has already been suggested. – xenoid – 2017-08-29T23:23:33.340