7

it was a normal day for me like any other day and I decided to open my Laptop for work and what I see the first is the following:

enter image description here

Then, I tried to find out what happened to these folders through the terminal and then I saw this:

enter image description here

And I tried to find a solution over the internet and found a lot of answers but nothing worked for me and when I try to cd into the Videos directory I get the following error:

bash: cd: Videos: Too many levels of symbolic links

which clearly states that this thing has fallen into a recursion hell which has no return as the directory is pointing itself and yet I don't have a clue why it happened and how to fix this. Moreover, my desktop also suddenly decided to start showing me the home directory contents on the screen when I had them turned off.

muru
  • 197,895
  • 55
  • 485
  • 740
Ayush
  • 282
  • 1
    Which version of Ubuntu are you using? I have been using Ubuntu for over 20 years and never seen Ubuntu doing anything on its own. Maybe you did something. If you don't tell us, we can't help. – user68186 Aug 19 '23 at 13:16
  • @user68186 Ubuntu 20.04.6 LTS and nowadays I'm working on the project ivy and I don't remember doing anything else expect for writing code and it's not just this time when ubuntu did something on its own it happened a lot of times before. It just needs a shutdown before it shows me something unexpected. – Ayush Aug 19 '23 at 14:33
  • see man xdg-user-dirs-update. But you have to find out by yourself, why this did not work in your case. As it works in general, there must be something special on your system. – Marco Aug 19 '23 at 16:54
  • 1
    I do have the exact same problem with Ubuntu 23.04: https://unix.stackexchange.com/questions/755324/inaccessible-folders-too-many-levels-of-symbolic-links. Deleting and recreating the folders (which were empty in my case) solved the problem. However, a few minutes later, they turned into symbolic links again. – TVG Aug 31 '23 at 08:01
  • https://askubuntu.com/questions/1488535/standard-user-directories-are-replaced-by-broken-symbolic-links This talks about the same issue that I had. The issue I had was from Okular causing issues. If you have it installed the fix is shown in the link I provided, essentially you just need to recreate the folders and put a hidden file in each of them so that they are not empty. – Nathan M Jan 23 '24 at 04:21

3 Answers3

6

Leaving this here for anyone experiencing the same issue. I was able to find a permanent solution for my case.

The culprit is Okular, the snap version to be specific. I used the solution provided by Melebius but noticed that the issue kept coming back. I came across this bug report and was able to recreate the issue at will by simply using the aforementioned solution for fixing it, then opening a document with Okular.

I uninstalled the snap version of Okular and that fixed the issue for me. I installed the .deb version via apt and everything seems to be working well.

Sol
  • 61
2

UPDATE: Boys, I thought this was a permanent fix but it seems out that this is just a temporary workaround. Once in a week the directories are turning themselves to symlinks by themselves.

I had to make a sacrifice, I deleted those directories! I sacrificed the directories and their contents; there wasn't much in them in my case but if it happens to you then you might have to do it too.

I deleted the directories and re-created those directories with the help of mkdir command (simple right?). But this time, I left an empty file inside of it and found that the problem is gone.

Regarding the desktop icons that suddenly decided to show up on the desktop screen, I wonder why the following didn't work:

  • gsettings set org.gnome.desktop.background show-desktop-icons false
  • gsettings set org.gnome.shell.extensions.desktop-icons show-home false

Neither it did work using the dconf-editor.

It worked many times before but this time it just didn't, but what worked in my case was disabling the desktop icons from the Extensions:

Look for the Extensions if it is already installed:

enter image description here

Disable the Desktop icons if it is enabled:

enter image description here

Ayush
  • 282
  • After recreating the Desktop folder, edit the file ~/.config/user-dirs.dirs from XDG_DESKTOP_DIR="$HOME/" to XDG_DESKTOP_DIR="$HOME/Desktop". The folder icons on your Desktop should return in your home/. – TVG Aug 31 '23 at 08:04
  • Are you sure your directories were not empty? In my case, the folders that automatically turn into symbolic links are always empty and it only happens to the directories listed in ~/.config/user-dirs.dirs. – TVG Aug 31 '23 at 09:20
  • All of the directories that turned into symbolic links in my case were all empty, I thought this might infect the other directories and I might loose my data. So I thought it would be better to ask for a cure before it happens. – Ayush Sep 01 '23 at 10:35
  • Same for me. Loosing the Desktop folder is annoying as all files and folders in home show up in the desktop. Loosing the Downloads folder is annoying too because it causes downloads from web browser to fail. – TVG Sep 04 '23 at 08:20
  • Are you using Timeshift or making automatic backups? I wonder if that could be linked in my case. – TVG Sep 04 '23 at 11:42
  • @TVG I'm not using timeshift and neither I remember installing any software that was unknown to me and could result in such a behaviour. – Ayush Sep 10 '23 at 07:49
  • Ok. For the moment, the only way I found to avoid the problem is to leave at least an empty file in each of the XDG directories. – TVG Sep 11 '23 at 08:16
2

I’ve run into this problem several times. I think it is related to system updates: It happens after installing some updates (not all). Just empty folders in the home folder are affected, so fortunately this does not cause any loss of actual data.

The temporary solution I am using:

Once you discover the problem, remove the broken symlinks (plain rm suffices), e.g.

~$ rm Desktop Public Templates Videos

Then run

xdg-user-dirs-update && xdg-user-dirs-update --force

to recreate the directories. The plain xdg-user-dirs-update command points the missing directories to ~ (if it’s not done already due to login), then --force recreates the directories:

$ xdg-user-dirs-update
/home/me/Desktop was removed, reassigning DESKTOP to homedir
/home/me/Templates was removed, reassigning TEMPLATES to homedir
/home/me/Public was removed, reassigning PUBLICSHARE to homedir
$ xdg-user-dirs-update --force
Moving DESKTOP directory from  to Desktop
Moving TEMPLATES directory from  to Templates
Moving PUBLICSHARE directory from  to Public
$
Melebius
  • 11,431
  • 9
  • 52
  • 78