背景

        不小心删除了/bin、/lib、/lib64和/sbin这些目录的软链接,导致系统中的各种命令都无法正常使用。在尝试多种方法后,包括添加环境变量和使用绝对路径执行命令无法恢复,最终不重装完美解决。

[root@centos-8 /]# ll
总用量 36
drwxr-xr-x     3 root     root       18 11月  1 00:00 app
lrwxrwxrwx     1 root     root        8 11月 14 15:52 bin -> /usr/bin
dr-xr-xr-x.    5 root     root     4096 11月  1 00:00 boot
drwxr-xr-x     3 postgres postgres   19 11月  1 00:00 data
drwxr-xr-x    19 root     root     3320 11月  1 00:00 dev
drwxr-xr-x.  131 root     root     8192 11月  1 00:00 etc
drwxr-xr-x.    3 root     root       22 11月  1 00:00 home
lrwxrwxrwx.    1 root     root        7 6月  22 2021 lib -> usr/lib
lrwxrwxrwx.    1 root     root        9 6月  22 2021 lib64 -> usr/lib64
drwxr-xr-x.    2 root     root        6 11月  1 00:00 media
drwxr-xr-x.    2 root     root        6 11月  1 00:00 mnt
drwxr-xr-x.    7 root     root       77 11月  1 00:00 opt
dr-xr-xr-x  1019 root     root        0 11月  1 00:00 proc
dr-xr-x---.    7 root     root     4096 11月  1 00:00 root
drwxr-xr-x    41 root     root     1160 11月  1 00:00 run
lrwxrwxrwx.    1 root     root        8 6月  22 2021 sbin -> usr/sbin
drwxr-xr-x.    2 root     root        6 11月  1 00:00 srv
dr-xr-xr-x    13 root     root        0 11月  1 00:00 sys
drwxrwxrwt.   68 root     root     8192 11月 14 15:52 tmp
drwxr-xr-x.   13 root     root      158 11月  1 00:00 usr
drwxr-xr-x.   21 root     root     4096 11月  1 00:00 var
drwxr-xr-x.    7 root     root       69 11月  1 00:00 web
[root@centos-8 /]# rm -rf bin lib lib64 sbin
[root@centos-8 /]# ll
-bash: /usr/bin/ls: 没有那个文件或目录
[root@centos-8 /]# ll
-bash: /usr/bin/ls: 没有那个文件或目录
[root@centos-8 /]# ln -s /usr/bin /bin
-bash: /usr/bin/ln: 没有那个文件或目录
[root@centos-8 /]# /usr/bin/ln -s /usr/bin /bin
-bash: /usr/bin/ln: 没有那个文件或目录
[root@centos-8 usr]# rz
-bash: /usr/bin/rz: 没有那个文件或目录
[root@centos-8 usr]# /usr/bin/rz
-bash: /usr/bin/lz: 没有那个文件或目录
[root@centos-8 usr]# /usr/bin/sz
-bash: /usr/bin/sz: 没有那个文件或目录
[root@centos-8 /]# export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/lib:/usr/lib64
[root@centos-8 /]# ln -s /usr/bin /bin

 解决方案

        此时只能执行cd pwd命令,登录也无法登录,网上找博客都是u盘恢复系统,因无法备份,放弃。        

        网上查找删除lib64恢复方法

绝对路径能找到,但是命令无法执行,找到库文件的绝对路径

[root@centos-8 /]# /usr/lib64/ld
ld-2.28.so            ldb/                  ld-linux-x86-64.so.2  
[root@centos-8 /]# /usr/lib64/ld-2.28.so /usr/bin/ln -s /usr/bin /bin
[root@centos-8 /]# /usr/lib64/ld-2.28.so /usr/bin/ln -s /usr/lib /lib
[root@centos-8 /]# /usr/lib64/ld-2.28.so /usr/bin/ln -s /usr/lib64 /lib64
[root@centos-8 /]# /usr/lib64/ld-2.28.so /usr/bin/ln -s /usr/sbin /sbin
[root@centos-8 /]# ll
总用量 36
drwxr-xr-x    3 root     root       18 11月  1 00:00 app
lrwxrwxrwx    1 root     root        8 11月 14 16:49 bin -> /usr/bin
dr-xr-xr-x.   5 root     root     4096 11月  1 00:00 boot
drwxr-xr-x    3 postgres postgres   19 11月  1 00:00 data
drwxr-xr-x   19 root     root     3320 11月  1 00:00 dev
drwxr-xr-x. 131 root     root     8192 11月  1 00:00 etc
drwxr-xr-x.   3 root     root       22 11月  1 00:00 home
lrwxrwxrwx    1 root     root        8 11月 14 16:50 lib -> /usr/lib
lrwxrwxrwx    1 root     root       10 11月 14 16:50 lib64 -> /usr/lib64
drwxr-xr-x.   2 root     root        6 11月  1 00:00 media
drwxr-xr-x.   2 root     root        6 11月  1 00:00 mnt
drwxr-xr-x.   7 root     root       77 11月  1 00:00 opt
dr-xr-xr-x  977 root     root        0 11月  1 00:00 proc
dr-xr-x---.   7 root     root     4096 11月 14 16:24 root
drwxr-xr-x   41 root     root     1160 11月  1 00:00 run
lrwxrwxrwx    1 root     root        9 11月 14 16:50 sbin -> /usr/sbin
drwxr-xr-x.   2 root     root        6 11月  1 00:00 srv
dr-xr-xr-x   13 root     root        0 11月  1 00:00 sys
drwxrwxrwt.  68 root     root     8192 11月 14 16:49 tmp
drwxr-xr-x.  13 root     root      158 11月  1 00:00 usr
drwxr-xr-x.  21 root     root     4096 11月  1 00:00 var
drwxr-xr-x.   7 root     root       69 11月  1 00:00 web

使用库文件绝对路径+命令绝对路径恢复删除的软连接

更多推荐