LinuxCommandLibrary

runlevel

Show current system runlevel

SYNOPSIS

runlevel

DESCRIPTION

The runlevel command in Linux is used to identify the current and previous system runlevels. Runlevels define the operating state of the system, determining which services and processes are running. Understanding runlevels is crucial for system administration, as it allows you to control the system's behavior during boot and runtime. The output typically consists of two characters: the previous runlevel and the current runlevel. If the system has booted directly into the current runlevel without transitioning from another, the first character will be 'N'. The command is typically used in system scripts and boot processes to determine the system's state. It's important to note that modern systems using systemd might not strictly adhere to traditional runlevels, using targets instead. In these cases, the 'runlevel' command might return 'N' for the previous runlevel or display an approximation of the runlevel based on the active systemd target.

The command is very simple and serves a single function. However, its output can be critical in complex scripts and automation where the system state matters.

CAVEATS

On systemd-based systems, runlevels are emulated via targets, and the runlevel command may not always accurately reflect the current system state. Relying solely on runlevel output in systemd environments may lead to unexpected behavior.

OUTPUT INTERPRETATION

The command outputs two characters:
N: No previous runlevel. This indicates that the system booted directly into the current runlevel.
0-6, S: The previous and current runlevels. These numerical values represent different system states (e.g., single-user mode, multi-user mode). Note that the meaning of each number is distribution specific.

EXAMPLE

If the output of runlevel is 'N 5', it means the system booted directly into runlevel 5 without transitioning from another runlevel. If the output is '3 5', it means that the previous runlevel was 3 and the current one is 5.

HISTORY

The runlevel command has been a standard part of Unix-like operating systems for a long time, tracing back to the traditional System V init system. It provided a crucial means for administrators to understand and manage system startup and shutdown processes. As Linux evolved, it inherited this command, preserving its functionality. With the adoption of systemd, the role of runlevels has been somewhat superseded by systemd targets, although runlevel remains as a compatibility command, often aliased to query the current systemd target.

SEE ALSO

init(8), systemctl(1), telinit(8)

Copied to clipboard