theboyaply
theboyaply
发布于 2020-04-11 / 2453 阅读
0
0

Centos 中误改 /etc/profile 文件怎么还原

/etc/profile 文件是 centos 系统中保存环境变量的文件,在开发中我们经常需要修改该文件来配置某种开发工具的环境变量。比如 java、maven 等等。

假如我们不小心配置错误了,并执行了 source /etc/profile 导致后续所有命令都提示无法找到,比如:

[root@tom ~]# vim /etc/profile
[root@tom ~]# source /etc/profile
[root@tom ~]# vim /etc/profile
-bash: vim: 未找到命令
[root@tom ~]# vi /etc/profile
-bash: vi: 未找到命令

此时我们可以按以下步骤还原:

# 指定 vi 或者 vim 编辑器修改该文件至正确
[root@tom ~]# /bin/vim /etc/profile

# 配置临时 PATH 的值
[root@tom ~]# export PATH=/usr/bin:/usr/sbin:/bin:/sbin

# 重新刷新配置文件
[root@tom ~]# source /etc/profile

-- end --


评论