误删Linux path中的路径恢复

转载请注明来源-作者@loongshawn:http://blog.csdn.net/loongshawn/article/details/51657268

相关文章:

  • 《 ping: unknown host 解决办法》
  • 《 MacPro 利用SCP上传下载Linux服务器文件》

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

恢复!

你可能感兴趣的