简记修复改etc下profile失败的补救措施

现象

下午配置环境变量一个小小的失误,把etc文件夹下的profile改崩了,导致很多基本命令都用不了,服务器出现了下面这种情况。

[root@xxxx ~]# vi /etc/profile
-bash: vi: command not found
[root@xxxxx~]# vi
-bash: vi: command not found
[root@xxxx ~]# ls
-bash: ls: command not found
[root@xxxx ~]# /bin/vi /etc/profile
[root@xxxx ~]# source /etc/profile
-bash: id: command not found
-bash: [: =: unary operator expected
[root@xxxx ~]# ll
-bash: ls: command not found
[root@xxxx ~]# ls
-bash: ls: command not found

可以看到,所有的命令都报找不到非常恐怖。

在这里插入图片描述

补救方式

强制还原profile

查阅网上资料笔者找到一个非常干脆的方式,首先我们强制使用死路径的方式执行bash的vim命令,将错误的环境变量配置删除后,键入wq退出。

/bin/vim /etc/profile

强制配置path

完成上述步骤之后,bash命令还是不能使用,所以我们还需要强行配置一下PATH变量。键入下面这段命令重置一下path,这里补充说明一下我们把profile改错之后导致所有环境变量都读不到,所以我们在命令行直接强写一下PATH,确保bash命令都能用,然后所有基本指令可以用之后,再用source命令即可还原所有。

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

然后键入下面这段命令,自此问题修复,这样以来所有的bash命令都可以用了。

source /etc/profile

参考

Linux – 04 – 修改/etc/profile失败补救方法

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-15 08:52:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-15 08:52:04       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-15 08:52:04       82 阅读
  4. Python语言-面向对象

    2023-12-15 08:52:04       91 阅读

热门阅读

  1. 【bash】Bash脚本基础语法学习

    2023-12-15 08:52:04       54 阅读
  2. Bash script进阶笔记

    2023-12-15 08:52:04       57 阅读
  3. Python多线程编程:竞争问题的解析与应对策略

    2023-12-15 08:52:04       53 阅读
  4. windows MinGW C语言编译器安装及环境变量配置教程

    2023-12-15 08:52:04       56 阅读
  5. LeetCode //C - 605. Can Place Flowers

    2023-12-15 08:52:04       59 阅读
  6. kafka3.X集群安装(不使用zookeeper)

    2023-12-15 08:52:04       52 阅读
  7. vue-quill-editor上传图片base64转化为img标签

    2023-12-15 08:52:04       61 阅读
  8. ubuntu-base 20.04防火墙配置方法

    2023-12-15 08:52:04       59 阅读
  9. 解释 Git 的基本概念和使用方式

    2023-12-15 08:52:04       58 阅读
  10. Webservice--HTTP,SOAP协议区别

    2023-12-15 08:52:04       45 阅读