
runlevel Command in Linux
Linux operating systems have different states called runlevels, which define what services and processes are running on the system. These runlevels range from 0 (halt) to 6 (reboot), and each runlevel has a specific purpose.
The runlevel command is crucial for administrators to identify the current and previous states of the system, helping them manage services and troubleshoot issues effectively. This command outputs two characters representing the previous and current runlevels, providing insight into the system's state transitions.
Table of Contents
Here is a comprehensive guide to the options available with the runlevel command −
Syntax of runlevel Command
The basic syntax for the runlevel command is quite simple, which is given below −
runlevel
When executed, this command outputs two characters representing the previous and current runlevels. If either character is N, it indicates that the runlevel has not been changed since the system was booted.
How to Use runlevel Command in Linux?
To determine the current and previous runlevels of your system, simply run −
runlevel
This command outputs two characters, where the first character represents the previous runlevel and the second character denotes the current runlevel.

Here, N indicates there was no previous runlevel since the system was booted directly into runlevel 5, which is a multi-user mode without a graphical interface.
If you see this output −
3 1
This means the system was previously at runlevel 3 (multi-user mode without a graphical interface) and is now at runlevel 1 (single-user mode).
You can also incorporate the runlevel command into scripts to automate system management tasks. For example −
#!/bin/bash latest_runlevel=$(runlevel | awk '{print $2}') echo "The current runlevel is $latest_runlevel"
This script fetches the current runlevel and displays it.
Conclusion
The runlevel command is an essential part of a system administrator's toolkit, offering straightforward yet powerful insight into the state of a Linux system. Understanding and utilizing this command allows you to efficiently manage runlevels, ensuring your services and processes operate as intended.
Implementing the runlevel command into your workflow enhances your ability to troubleshoot, optimize, and maintain your system's health. Continue to explore more advanced uses and scripts that can integrate the power of runlevel for a robust and secure Linux environment.