runlevel - report previous and current Unix OS runlevel

Hi! If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

runlevel is a basic Unix command aimed to do one simple task: report the runlevel of your Unix OS.

How runlevel command works

Your Unix system carefully logs information about every login session in special files. /var/run/utmp is the file containing information about everyone who's currently logged in, and since every record contains a runlevel information, it makes sense to use this file as a proof of the current OS runlevel.

runlevel command reads /var/run/utmp file and extracts the most recent login entry. It then uses this entry to extract the current and previous runlevel information from it.

Using runlevel command

Simply run the command without any parameters:

redhat$ runlevel
N 5

As it was said earlier, the two numbers shown are supposed to be previous and current Unix runlevels.

However, the previous runlevel information is not usually found in the most recent login entry simply because runlevel hasn't changed,

so the command prints "N" instead of it.

Looking at the output above, you can see that the current runlevel is 5.

See also:

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Fark
  • Furl
  • Netscape
  • Reddit
  • Smarking
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb

1 comment so far ↓

#1 Updating Values of Your Shell Variables in Unix | UNIX Tutorial: Learn UNIX on 08.29.08 at 4:35 am

[...] like the runlevel command, it's quite simple and can be useful in scripts. When I attempt to run it, here's what [...]

Leave a Comment