1. 程式人生 > >誤刪Linux path中的路徑恢復

誤刪Linux path中的路徑恢復

相關文章:

1、場景

誤刪Linux path配置的原始路徑,導致shell的基本操作命令失效,如vi、cat、source等。

2、操作

登陸Linux系統,檢視當前的path路徑:

echo $PATH
/opt/java/jdk1.8.0_45/bin:/opt/alibaba-rocketmq/bin:/opt/java/jdk1.8.0_45//bin:/opt/alibaba-rocketmq/bin:/opt/java/jdk1.8.0_45//bin:/opt/alibaba-rocketmq/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/X11R6/bin
:/home/dddd/bin

檢視正常時的路徑:

vi /etc/profile
export PATH=$JAVA_HOME/bin:$ROCKETMQ_HOME/bin:$PATH

由於疏忽,將上述路徑修改為了:

export PATH=$JAVA_HOME/bin:$ROCKETMQ_HOME/bin

修改後儲存

source /etc/profile
echo $PATH
/opt/java/jdk1.8.0_45/bin:/opt/alibaba-rocketmq/bin

坑爹的來了,接下來shell命令就失效了…

vi /etc/profile
-bash: sudo: command not
found
source /etc/profile -bash: id: command not found -bash: id: command not found -bash: id: command not found -bash: tty: command not found cat /etc/profile -bash: cat: command not found

因為已經找不到所執行命令的路徑了。

3、恢復

執行命令,把PATH後面的$PATH加上。

/usr/bin/sudo /bin/vi /etc/profile

生效變更。

source /etc/profile
-bash:
id: command not found -bash: id: command not found -bash: id: command not found -bash: tty: command not found export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11R6/bin

恢復!