-1

A few days ago I found the following command:

for i in 0 1 2 3 4 5 6 S ; do ln -s /etc/rc$i.d /etc/rc.d/rc$i.d ; done

As far as understand this command is going to create a symbolic link between each file using the for cycle, but what I can't really understand is the S in that numeration, what is it supposed to do?

  • It's an S. Much like the one at the end of my previous sentence. – Ignacio Vazquez-Abrams Feb 19 '18 at 1:13
1

Those numbers aren't randomly selected, they're the runlevels of your system. The runlevel used to determine which init scripts are run. They're mostly obsolete now. And if you're on Linux, it's highly likely that the runlevels S and 1 are the same. Your documents might be really old, or they'd probably be using update-rc.d instead of manually creating symlinks.

So your loop is iterating over all runlevels, 1-6 and S.

  • Okay, so if I understand correctly this is creating a symlink to the each of the initialization scripts? Now this really makes sense, thank you. – spurdosparde Feb 19 '18 at 1:26
  • @spurdosparde yes. But if you're on popular Linux distros like Ubuntu, Debian, Fedora, CentOS, this is just supported for backwards compatibility, so there's not much to be gained from digging too much into it. – Olorin Feb 19 '18 at 1:29
0

All items after the 'in' in the for loop are strings that will be assigned to $i in the loop. The script will create soft links from /etc/rc?.d into /etc/rc.d/rc?.d. This is probably a bit of a hack to ensure some sort of compatibility between distros.

S is sometimes used as a synonym to runlevel 1 or single-user mode. https://en.wikipedia.org/wiki/Runlevel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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