Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

In a python script, I am creating a bunch of symbolic links chained together.

example: link1->link2->link3->.......->somefile.txt

I was wondering how you can change the max number of symlinks to be greater than 20?

share|improve this question
Why would you want to do this? MAXSYMLINKS is defined in system headers (e.g. /usr/include/x86_64-linux-gnu/sys/param.h on my system), and is not intended to be modified by users. – ire_and_curses Oct 28 '12 at 5:57
Having to call readlink() over 20 times to get to a real file is not going to be good for performance. – jordanm Oct 28 '12 at 13:55
I am taking an ethical hacking class at school, which is pretty cool.One of the HACKS is called TOCTTOU, where you want to impact the performance by creating an elaborate directory/symbolic link maze. – grebwerd Nov 1 '12 at 21:23
up vote 6 down vote accepted

On Linux (3.5 at least), it's hardcoded to 40 (see follow_link() in fs/namei.c), and note that it's the number of links followed when resolving all the components of a path, you can only change it by recompiling the kernel.

$ ln -s . 0
$ n=0; repeat 50 ln -s $((n++)) $n
$ ls -LdF 39
$ ls -LdF 40
ls: cannot access 40: Too many levels of symbolic links
$ ls -LdF 20/18 10/10/10/6
10/10/10/6/  20/18/
$ ls -LdF 20/19 10/10/10/7
ls: cannot access 20/19: Too many levels of symbolic links
ls: cannot access 10/10/10/7: Too many levels of symbolic links
share|improve this answer

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.