Skip to content

/errors/coreutils/too-many-levels-of-symbolic-links

Too many levels of symbolic links

verified onenvironmentlocal · linux 6.18.44-fc-v140 x64 · GNU bash 5.2.21 · ls (GNU coreutils) 9.4updated
tool
GNU coreutils
exit code
1
versions
GNU coreutils 8.x, GNU coreutils 9.x
os
linux, macos

Too many levels of symbolic links is the text of the ELOOP error. The kernel follows a limited number of symbolic links while resolving one path, and gives up when a link points back to itself or when the chain is too long. The fix is to find the cycle and replace one of its links.

Reproduce it

bash
ln -s b a
ln -s a b
cat a

Output · exit 1

cat: a: Too many levels of symbolic links

a points to b and b points to a, so the path never resolves to a file.

Find the cycle

bash
ln -s b a
ln -s a b
readlink a
readlink b
readlink -e a || echo "no target"

Output

b
a
no target

readlink without options prints one link target per call and does not follow the chain, so it works on a loop. readlink -e follows the whole chain and fails when it cannot resolve it.

Fix it

bash
echo data > real.txt
ln -s real.txt a
cat a

Output

data

Sources