Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I deleted a critical symbolic link - I have the file it should point at, but the basic commands such as ln or wget won't work anymore due to the link missing. However, echo or other Bash builtins work.

I am looking for a way to recreate this symbolic link.

share|improve this question
@Sebas, I think you meant all the Bash builtins, not just echo. – Cristian Ciupitu May 10 '14 at 18:25
@CristianCiupitu maybe, what is it? cat is disabled... actually everything was. – Sebas May 10 '14 at 18:27
@Sebas, that's because cat is an external program. The Bash Builtin Commands manual page has details about what could be available. – Cristian Ciupitu May 10 '14 at 18:30
I assume you mean GNU/Linux based systems when you say "Unix" as many other *nix systems have "rescue" versions of the standard utilities that are statically linked just for those "oops" moments. – Chris S May 10 '14 at 19:38
I adjusted the flags. Thank you – Sebas May 10 '14 at 20:13
up vote 58 down vote accepted

you can use ldconfig, it recreates the symlink:

# rm /lib/ 
rm: remove symbolic link `/lib/'? y
# ls -l /lib/libc*
ls: error while loading shared libraries: cannot open shared object file:
# ldconfig 
# ls -l /lib/libc*
lrwxrwxrwx. 1 root root      12 May 11 07:59 /lib/ ->

just tested it, as you see.

share|improve this answer
And, conveniently, the /sbin/ldconfig is statically linked. ldconfig is responsible for those symbolic links in the first place. – etherfish May 11 '14 at 8:49
That's not really just "convenient", a statically-linked binary is pretty much a necessary design component of the tool that maintains your dynamic libraries! But it is what makes it an ideal tool for fixing this problem, and IMHO the only "correct" way. The question here is really not about a deleted symlink (99.999% of those can be deleted without consequence), it's "I broke my system's dynamic library store". Making @natxo's suggestion, "fix it using the tool that manages that store", obvious and sensible. Anything else (manually recreating the link) is a hacky workaround. – FeRD May 11 '14 at 22:39
Yes, this is indeed more logical to proceed so even though the other answer was correct too. – Sebas May 12 '14 at 15:54

CentOS 6 generally comes with busybox, a statically-linked set of Unix tools, installed in /sbin. You can run it like this:

/sbin/busybox ln -s /lib/
share|improve this answer
+1, just tested it after removing the symlink in a test vm, it woks in centos 6.5 – natxo asenjo May 11 '14 at 5:52
+1 This answers the generic question in the question title as well. – MattBianco May 13 '14 at 12:05

Set LD_PRELOAD to preload the relevant library. I tried it out with libpthread and it seems to work:

root@spirit:~# mv /lib/x86_64-linux-gnu/ /lib/x86_64-linux-gnu/
root@spirit:~# chattr
chattr: error while loading shared libraries: cannot open shared object file: No such file or directory
root@spirit:~# LD_PRELOAD=/lib/x86_64-linux-gnu/ chattr
Usage: chattr [-RVf] [-+=AaCcDdeijsSu] [-v version] files...
share|improve this answer
interesting, it regroups with what the others said. – Sebas May 10 '14 at 20:13

sln serves exactly that purpose: to fix symbolic links when you can't use regular ln because you broke an essential symlink. To quote its man page:


  The  sln  program creates symbolic links.  Unlike the ln(1) program, it
  is statically linked.  This means that if for some reason  the  dynamic
  linker  is  not  working,  sln  can  be  used to make symbolic links to
  dynamic libraries.
share|improve this answer
nice, I did not know this tool. In centos it is part of glibc, so it must be installed by default – natxo asenjo May 12 '14 at 11:31
thanks for your input – Sebas May 12 '14 at 15:55

You can set LD_LIBRARY_PATH variable to include the directory where real is:


Also, execute ldconfig for it to recreate the links. This should make the commands work so you can then use ln commands to fix your system.

Another way would be to boot via LiveCD and link file there.

share|improve this answer
Then only way to boot off livecd and link file there in chroot. – phoops May 10 '14 at 18:15
Also, you should just set LD_LIBRARY_PATH to include directory where file is. This might let you use the commands as it should find the lib. – phoops May 10 '14 at 18:20
darn, sorry I didn't think of this first. – phoops May 10 '14 at 18:31
That doesn't work, becuase the file linked to isn't named You'll need to set LD_PRELOAD as in my answer. – Dennis Kaarsemaker May 10 '14 at 19:39
I tried it on Fedora 20 and it didn't work. – Cristian Ciupitu May 10 '14 at 20:53

Use scp or sftp to copy a statically linked version of ln. Make sure it is executable. Then use it to fix the file.

share|improve this answer
scp and sftp will not work as they will not be able to load that file either. – Florin Asăvoaie May 14 '14 at 0:18
scp, sftp, ftp would be run from a remote host. This assumes that the daemon in the broken machine is running already. Other possibilities for file transfer are file systems that are already mounted, either local or remote. – Robert Jacobs May 14 '14 at 18:33
Please stop misinformation. SCP requires the scp binary to be present and will be executed on both hosts. SFTP also launches new processes out of OpenSSH that require the respective binary. Most of the FTP daemons do the same. – Florin Asăvoaie May 15 '14 at 5:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.