26

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?

Robin Green
  • 1,275
  • 1
  • 13
  • 28
Lokomotywa
  • 373
  • 3
  • 7

3 Answers3

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
  • 153,128
  • 77
  • 353
  • 394
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
  • 1,031
  • 7
  • 18
  • 1
    And remove the spaces! `PATH=something`, NOT `PATH = something` – waltinator Nov 13 '15 at 21:46
  • 4
    That 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 Nov 13 '15 at 22:22
  • @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 Nov 14 '15 at 01:34
  • 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 Nov 14 '15 at 09:29
-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!