2

I was recently trying to resolve an issue regarding a mismatch in the version of my java jre and java compiler, so I tried something suggested in this answer, which seemed to be relatively harmless, with lots of upvotes and was the selected answer to the exact right question: https://stackoverflow.com/questions/10585091/resolving-version-conflict-between-java-and-javac-on-ubuntu

however, unfortunately I did not use my brain before executing the following command, which would be the suggested command in my case:

sudo ln -s -f /usr/bin/* /usr/bin

After some more thought, I realize that this is symbolically linking every file in the /usr/bin directory back to the parent directory, thus creating a cyclical file structure that goes on adfinitum. So, a nightmare.

when I try ls -l in my /usr/bin directory, I get a bunch of entries that look like:

-rwxr-xr-r 1 root root 5518 Feb 12 2014 xzcat -> /usr/bin/xzcat

But of course there is some simple way of undoing this? The issue is that I am not sure what files I can delete, since no files were actually added in this process.

Any thoughts?

Here is the output of my command:

ln: ‘/usr/bin/[’ and ‘/usr/bin/[’ are the same file
ln: ‘/usr/bin/2to3-2.7’ and ‘/usr/bin/2to3-2.7’ are the same file
ln: ‘/usr/bin/2to3-3.4’ and ‘/usr/bin/2to3-3.4’ are the same file
ln: ‘/usr/bin/2to3-3.5’ and ‘/usr/bin/2to3-3.5’ are the same file
ln: ‘/usr/bin/a2p’ and ‘/usr/bin/a2p’ are the same file
ln: ‘/usr/bin/ab’ and ‘/usr/bin/ab’ are the same file
ln: ‘/usr/bin/aclocal-1.15’ and ‘/usr/bin/aclocal-1.15’ are the same file
ln: ‘/usr/bin/aconnect’ and ‘/usr/bin/aconnect’ are the same file
ln: ‘/usr/bin/acpi_listen’ and ‘/usr/bin/acpi_listen’ are the same file
ln: ‘/usr/bin/activity-log-manager’ and ‘/usr/bin/activity-log-manager’ are the same file
ln: ‘/usr/bin/add-apt-repository’ and ‘/usr/bin/add-apt-repository’ are the same file
ln: ‘/usr/bin/addpart’ and ‘/usr/bin/addpart’ are the same file
ln: ‘/usr/bin/addr2line’ and ‘/usr/bin/addr2line’ are the same file
ln: ‘/usr/bin/alsaloop’ and ‘/usr/bin/alsaloop’ are the same file
ln: ‘/usr/bin/alsamixer’ and ‘/usr/bin/alsamixer’ are the same file
ln: ‘/usr/bin/alsaucm’ and ‘/usr/bin/alsaucm’ are the same file
ln: ‘/usr/bin/amidi’ and ‘/usr/bin/amidi’ are the same file
ln: ‘/usr/bin/amixer’ and ‘/usr/bin/amixer’ are the same file
ln: ‘/usr/bin/amuFormat.sh’ and ‘/usr/bin/amuFormat.sh’ are the same file
ln: ‘/usr/bin/apg’ and ‘/usr/bin/apg’ are the same file
ln: ‘/usr/bin/apgbfm’ and ‘/usr/bin/apgbfm’ are the same file
ln: ‘/usr/bin/aplay’ and ‘/usr/bin/aplay’ are the same file
ln: ‘/usr/bin/aplaymidi’ and ‘/usr/bin/aplaymidi’ are the same file
ln: ‘/usr/bin/apport-bug’ and ‘/usr/bin/apport-bug’ are the same file
ln: ‘/usr/bin/apport-cli’ and ‘/usr/bin/apport-cli’ are the same file
ln: ‘/usr/bin/apport-unpack’ and ‘/usr/bin/apport-unpack’ are the same file
ln: ‘/usr/bin/appres’ and ‘/usr/bin/appres’ are the same file
ln: ‘/usr/bin/apt’ and ‘/usr/bin/apt’ are the same file
ln: ‘/usr/bin/apt-cache’ and ‘/usr/bin/apt-cache’ are the same file
ln: ‘/usr/bin/apt-cdrom’ and ‘/usr/bin/apt-cdrom’ are the same file
ln: ‘/usr/bin/apt-config’ and ‘/usr/bin/apt-config’ are the same file
ln: ‘/usr/bin/aptdcon’ and ‘/usr/bin/aptdcon’ are the same file
ln: ‘/usr/bin/apt-extracttemplates’ and ‘/usr/bin/apt-extracttemplates’ are the same file
ln: ‘/usr/bin/apt-ftparchive’ and ‘/usr/bin/apt-ftparchive’ are the same file
ln: ‘/usr/bin/apt-get’ and ‘/usr/bin/apt-get’ are the same file
ln: ‘/usr/bin/apt-key’ and ‘/usr/bin/apt-key’ are the same file
ln: ‘/usr/bin/apt-mark’ and ‘/usr/bin/apt-mark’ are the same file
ln: ‘/usr/bin/apt-sortpkgs’ and ‘/usr/bin/apt-sortpkgs’ are the same file
ln: ‘/usr/bin/apturl’ and ‘/usr/bin/apturl’ are the same file
ln: ‘/usr/bin/apturl-gtk’ and ‘/usr/bin/apturl-gtk’ are the same file
ln: ‘/usr/bin/ar’ and ‘/usr/bin/ar’ are the same file
ln: ‘/usr/bin/arch’ and ‘/usr/bin/arch’ are the same file
ln: ‘/usr/bin/arecordmidi’ and ‘/usr/bin/arecordmidi’ are the same file
ln: ‘/usr/bin/arm2hpdl’ and ‘/usr/bin/arm2hpdl’ are the same file
ln: ‘/usr/bin/arping’ and ‘/usr/bin/arping’ are the same file
ln: ‘/usr/bin/as’ and ‘/usr/bin/as’ are the same file
ln: ‘/usr/bin/aseqdump’ and ‘/usr/bin/aseqdump’ are the same file
ln: ‘/usr/bin/aseqnet’ and ‘/usr/bin/aseqnet’ are the same file
ln: ‘/usr/bin/aspell’ and ‘/usr/bin/aspell’ are the same file
ln: ‘/usr/bin/aspell-import’ and ‘/usr/bin/aspell-import’ are the same file
ln: ‘/usr/bin/atobm’ and ‘/usr/bin/atobm’ are the same file
ln: ‘/usr/bin/autoconf’ and ‘/usr/bin/autoconf’ are the same file
ln: ‘/usr/bin/autoheader’ and ‘/usr/bin/autoheader’ are the same file
ln: ‘/usr/bin/autom4te’ and ‘/usr/bin/autom4te’ are the same file
ln: ‘/usr/bin/automake-1.15’ and ‘/usr/bin/automake-1.15’ are the same file

...

Note that this error does not occurr for every file, just most of them.

This is the output of

`ls -la | grep '\->'
lrwxrwxrwx  1 root   root          13 May 23 19:16 2to3 -> /usr/bin/2to3
lrwxrwxrwx  1 root   root          16 May 23 19:16 aclocal -> /usr/bin/aclocal
lrwxrwxrwx  1 root   root          10 Sep  3  2015 add-patch -> edit-patch
lrwxrwxrwx  1 root   root          21 May 23 19:16 appletviewer -> /usr/bin/appletviewer
lrwxrwxrwx  1 root   root          23 May 23 19:16 apport-collect -> /usr/bin/apport-collect
lrwxrwxrwx  1 root   root          16 May 23 19:16 apropos -> /usr/bin/apropos
lrwxrwxrwx  1 root   root          27 May 23 19:16 apt-add-repository -> /usr/bin/apt-add-repository
lrwxrwxrwx  1 root   root          16 May 23 19:16 arecord -> /usr/bin/arecord
lrwxrwxrwx  1 root   root          18 May 23 19:16 assistant -> /usr/bin/assistant
lrwxrwxrwx  1 root   root           2 Jan 10  2015 atq -> at
lrwxrwxrwx  1 root   root           2 Jan 10  2015 atrm -> at
lrwxrwxrwx  1 root   root          17 May 23 19:16 automake -> /usr/bin/automake
lrwxrwxrwx  1 root   root          29 May 23 19:16 avahi-browse-domains -> /usr/bin/avahi-browse-domains
lrwxrwxrwx  1 root   root          30 May 23 19:16 avahi-publish-address -> /usr/bin/avahi-publish-address
lrwxrwxrwx  1 root   root          30 May 23 19:16 avahi-publish-service -> /usr/bin/avahi-publish-service
lrwxrwxrwx  1 root   root          30 May 23 19:16 avahi-resolve-address -> /usr/bin/avahi-resolve-address
lrwxrwxrwx  1 root   root          32 May 23 19:16 avahi-resolve-host-name -> /usr/bin/avahi-resolve-host-name
lrwxrwxrwx  1 root   root          21 May 24 18:16 awk -> /etc/alternatives/awk
lrwxrwxrwx  1 root   root          12 May 23 19:16 c++ -> /usr/bin/c++
lrwxrwxrwx  1 root   root          12 May 23 19:16 c89 -> /usr/bin/c89
lrwxrwxrwx  1 root   root          12 May 23 19:16 c99 -> /usr/bin/c99
lrwxrwxrwx  1 root   root          12 May 23 19:16 cal -> /usr/bin/cal
lrwxrwxrwx  1 root   root          18 May 23 19:16 captoinfo -> /usr/bin/captoinfo
lrwxrwxrwx  1 root   root          11 May 23 19:16 cc -> /usr/bin/cc
lrwxrwxrwx  1 root   root          17 May 23 19:16 cdrecord -> /usr/bin/cdrecord
lrwxrwxrwx  1 root   root          14 May 23 19:16 chacl -> /usr/bin/chacl
lrwxrwxrwx  1 root   root          16 May 23 19:16 chardet -> /usr/bin/chardet
lrwxrwxrwx  1 root   root          17 May 23 19:16 chardet3 -> /usr/bin/chardet3
lrwxrwxrwx  1 root   root          16 May 23 19:16 charmap -> /usr/bin/charmap
lrwxrwxrwx  1 root   root          20 May 23 19:16 combinediff -> /usr/bin/combinediff
lrwxrwxrwx  1 root   root          16 May 23 19:16 compose -> /usr/bin/compose
lrwxrwxrwx  1 root   root          12 May 23 19:16 cpp -> /usr/bin/cpp
lrwxrwxrwx  1 root   root          14 May 23 19:16 ctags -> /usr/bin/ctags
lrwxrwxrwx  1 root   root          15 May 23 19:16 ctstat -> /usr/bin/ctstat
lrwxrwxrwx  1 root   root           8 Sep  3  2015 cvs-debc -> cvs-debi
lrwxrwxrwx  1 root   root           9 Sep  3  2015 dch -> debchange
lrwxrwxrwx  1 root   root           4 Sep  3  2015 debc -> debi
lrwxrwxrwx  1 root   root          17 May 23 19:16 designer -> /usr/bin/designer
lrwxrwxrwx  1 root   root          26 May 23 19:16 desktop-file-edit -> /usr/bin/desktop-file-edit
lrwxrwxrwx  1 root   root          16 May 23 19:16 dh_pypy -> /usr/bin/dh_pypy
lrwxrwxrwx  1 root   root          19 May 23 19:16 dh_python3 -> /usr/bin/dh_python3
lrwxrwxrwx  1 root   root          16 May 23 19:16 dotlock -> /usr/bin/dotlock
lrwxrwxrwx  1 root   root          17 May 23 19:16 dumpkeys -> /usr/bin/dumpkeys
lrwxrwxrwx  1 root   root          16 May 23 19:16 ebrowse -> /usr/bin/ebrowse
lrwxrwxrwx  1 root   root          13 May 23 19:16 edit -> /usr/bin/edit
lrwxrwxrwx  1 root   root          15 May 23 19:16 editor -> /usr/bin/editor
lrwxrwxrwx  1 root   root          14 May 23 19:16 emacs -> /usr/bin/emacs
lrwxrwxrwx  1 root   root          16 May 23 19:16 emacs24 -> /usr/bin/emacs24
lrwxrwxrwx  1 root   root          20 May 23 19:16 emacsclient -> /usr/bin/emacsclient
lrwxrwxrwx  1 root   root          14 May 23 19:16 etags -> /usr/bin/etags
lrwxrwxrwx  1 root   root          11 May 23 19:16 ex -> /usr/bin/ex
lrwxrwxrwx  1 root   root          17 May 23 19:16 extcheck -> /usr/bin/extcheck
lrwxrwxrwx  1 root   root          12 May 23 19:16 f77 -> /usr/bin/f77
lrwxrwxrwx  1 root   root          12 May 23 19:16 f95 -> /usr/bin/f95
lrwxrwxrwx  1 root   root          17 May 23 19:16 fakeroot -> /usr/bin/fakeroot
lrwxrwxrwx  1 root   root          16 May 23 19:16 firefox -> /usr/bin/firefox
lrwxrwxrwx  1 root   root          17 May 23 19:16 flipdiff -> /usr/bin/flipdiff
lrwxrwxrwx  1 root   root          23 May 23 19:16 foo2zjs-icc2ps -> /usr/bin/foo2zjs-icc2ps
lrwxrwxrwx  1 root   root          21 May 23 19:16 foomatic-rip -> /usr/bin/foomatic-rip
lrwxrwxrwx  1 root   root          12 May 23 19:16 frm -> /usr/bin/frm
lrwxrwxrwx  1 root   root          13 May 23 19:16 from -> /usr/bin/from
lrwxrwxrwx  1 root   root          12 May 23 19:16 ftp -> /usr/bin/ftp
lrwxrwxrwx  1 root   root          12 May 23 19:16 g++ -> /usr/bin/g++
lrwxrwxrwx  1 root   root          12 May 23 19:16 gcc -> /usr/bin/gcc
lrwxrwxrwx  1 root   root          15 May 23 19:16 gcc-ar -> /usr/bin/gcc-ar
lrwxrwxrwx  1 root   root          15 May 23 19:16 gcc-nm -> /usr/bin/gcc-nm
lrwxrwxrwx  1 root   root          19 May 23 19:16 gcc-ranlib -> /usr/bin/gcc-ranlib
lrwxrwxrwx  1 root   root          18 May 23 19:16 gconftool -> /usr/bin/gconftool
lrwxrwxrwx  1 root   root          13 May 23 19:16 gcov -> /usr/bin/gcov
lrwxrwxrwx  1 root   root          18 May 23 19:16 gcov-tool -> /usr/bin/gcov-tool
lrwxrwxrwx  1 root   root          13 May 23 19:16 geqn -> /usr/bin/geqn
lrwxrwxrwx  1 root   root          12 May 23 19:16 GET -> /usr/bin/GET
lrwxrwxrwx  1 root   root          16 May 23 19:16 getfacl -> /usr/bin/getfacl
lrwxrwxrwx  1 root   root          17 May 23 19:16 gfortran -> /usr/bin/gfortran

...

EDIT: following @Stephen Kitt's advice, I am trying to use debsums to solve this problem. It took some work to get the debsums package to download properly given that so many programs are broken, but I finally was able to run debsums -c. This is the output:

sh: 1: awk: Too many levels of symbolic links
sh: 1: awk: Too many levels of symbolic links
sh: 1: awk: Too many levels of symbolic links
sh: 1: awk: Too many levels of symbolic links
sh: 1: awk: Too many levels of symbolic links
sh: 1: awk: Too many levels of symbolic links
sh: 1: awk: Too many levels of symbolic links
sh: 1: awk: Too many levels of symbolic links

So it appears debsums is not installing correctly.

EDIT: after fixing awk, I was able to run debsums, and now I am getting the following output:

/boot/vmlinuz-4.2.0-16-generic
/usr/lib/python3/dist-packages/cupshelpers/__pycache__/__init__.cpython-34.pyc
/usr/lib/python3/dist-packages/cupshelpers/__pycache__/config.cpython-34.pyc
/usr/lib/python3/dist-packages/cupshelpers/__pycache__/cupshelpers.cpython-34.pyc
/usr/lib/python3/dist-packages/cupshelpers/__pycache__/installdriver.cpython-34.pyc
/usr/lib/python3/dist-packages/cupshelpers/__pycache__/openprinting.cpython-34.pyc
/usr/lib/python3/dist-packages/cupshelpers/__pycache__/ppds.cpython-34.pyc
/usr/lib/python3/dist-packages/cupshelpers/__pycache__/xmldriverprefs.cpython-34.pyc

While this is encouraging, I am a bit concerned that it is missing a lot of changes. Given all of the symlinks that were deleted (>100) from many different parts of my /usr/bin directory, it is a bit strange that all of the changes are in my python library. Does this not seem highly unlikely or is debsums actually working correctly?

OK assuming all I need to do is replace my python3 installation, how to I do that? I still don't understand how to use dpkg to download this file. when I search using dpkg -S python3, I get the names of the packages, not the .deb files. but simply googling it and downloading the relevant .deb file doesn't place the file in the right location. I know this sounds like a simple question to some but I still don't know how to do this basic thing that will allow me to fix the problem.

8
  • Do you have a backup? :(
    – Lee-Man
    May 24, 2016 at 1:14
  • no. but luckily its a new computer and the only major app I have worked on so far is in git. but still, there must be some way to undo this command?
    – Paul
    May 24, 2016 at 1:18
  • No, you used the -f "force" switch, which forces the removal of existing destination files, so there is no easy way to undo the command. Take it as a lesson about your rootly power to shoot yourself in the foot. And as a lesson about backups. :)
    – Wildcard
    May 24, 2016 at 1:26
  • The other answer didn't say you should link things in /usr/bin that are already in there! It was obviously referring to a different location, and creating links in /usr/bin to point there. The disastrous command was your own invention.
    – user41515
    May 24, 2016 at 2:15
  • 3
    In my experiment just now, ln -sf refused to replace a regular file with a symlink to itself. That's where you got your "are the same file" messages. But it did replace existing symlinks (whether valid or broken) with self-symlinks. So the files you've lost are the ones that were symlinks already (e.g. xzcat -> xz). It should be possible to reconstruct them with a little effort. Restoring from backup would be the quickest way. Aside from that, dpkg -S them and apt-get install --reinstall, assuming that dpkg and apt-get haven't stopped working
    – user41515
    May 24, 2016 at 2:34

2 Answers 2

4

As you figured out, ln only replaced symlinks. Fixing this will involve at least reinstalling the packages which provide the missing symlinks...

Using find's -L option combined with the -type l test allows broken symlinks to be identified; then dpkg -S will identify the corresponding package in most cases:

dpkg -S $(find -L /usr/bin -type l)

Filtering this and feeding it to apt-get allows the packages to be reinstalled:

apt-get --reinstall install $(dpkg -S $(find -L /usr/bin -type l) | grep -v "diversion by" | cut -d: -f1)

This will still leave some broken symlinks, mostly corresponding to alternatives in /etc/alternatives; these can be fixed using something like

for file in $(find -L /usr/bin -type l -printf "%f\n"); do \
    if [ -e "/etc/alternatives/${file}" ]; then \
        ln -sf "/etc/alternatives/${file}" "/usr/bin/${file}"; \
    fi; \
done

(You'll probably want to replace ln -sf with echo to check what's going to be done...)

(I had previously suggested using debsums, but that doesn't work because symlinks aren't hashed.)

8
  • thanks for you response. Unfortunately debsums appears to be broken, but I think I can still get there this way. When I try to apt-get install debsums, an error occurrs because of a problem with the package "ucf". However, I am not sure what .deb file to download (dpkg -S does not tell me this). And googling ".deb file for package ucf" also turns up no obvious answers. Any idea what .deb file I need to dpkg?
    – Paul
    May 24, 2016 at 19:02
  • You can find packages on Debian's site, by name or by content; ucf is in the ucf package (click on the "all" link at the bottom for the list of download locations). May 24, 2016 at 19:08
  • I am moving my comments on this approach to my answer because they are getting too long
    – Paul
    May 24, 2016 at 19:14
  • @Paul you need to fix awk, see my updated answer. May 24, 2016 at 21:21
  • so I removed the existing symlink and then created the one you gave above, and now debsum -c gives an output that makes sense. the only issue is that the command you gave for reinstallation gives the error cut: the delimiter must be a single character.
    – Paul
    May 24, 2016 at 22:42
-1

no way it should create those symbolic links on same path with the same filenames as the origin. it should throw an error that file exist already.

to prove that it will not, here's the output in my vm on same distro with same command.

enter image description here

9
  • but I used the -f option. Does that mean I'm screwed?
    – Paul
    May 24, 2016 at 1:45
  • no, even if you used -f switch it will not create the file
    – RDCortez
    May 24, 2016 at 1:48
  • I received the same errors as you for the majority of the files affected. However, some of them did not produce an error, and those are exactly the ones that show up with symbolic links when I type ls -l. The one encouraging fact is that those files do not have size 0, so I don't think the destination files were deleted by the force, as @wildcard suggests. But I may be wrong (hopefully not!)
    – Paul
    May 24, 2016 at 2:10
  • those files that got replaced with -f switch were also symbolic files which you can restore by manually relinking them back to /usr/bin from their origin location e.g locate is located in /etc/alternatives/locate , you can link it back to /usr/bin by doing sudo ln -s -f /etc/alternatives/locate /usr/bin then you can use locate command again e.g locate python whatever.
    – RDCortez
    May 24, 2016 at 2:26
  • it's a pain to do it manually but it can be done and also thru script if you know how to make one. that's just the way it is, the price you pay for thinking the outcome of your action.
    – RDCortez
    May 24, 2016 at 2:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .