The Wayback Machine - https://web.archive.org/web/20240927074954/https://www.geeksforgeeks.org/init-command-in-linux-with-examples/
Open In App

init command in Linux with examples

Last Updated : 10 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The init process is the parent of all processes in Linux, identified by the process ID (PID) of 1. It is the first process that starts when a computer boots up and continues to run until the system shuts down. The term init stands for “initialization,” and its primary role is to create and manage processes based on instructions from configuration scripts, specifically those stored in the ‘/etc/inittab‘ file. As the last step of the kernel boot sequence, ‘init’ is crucial for the initialization and overall functioning of the system.

Role of the ‘init’ Command

The ‘init’ command initializes the system by executing scripts that set up the operating environment. These scripts, known as “init scripts” or “rc scripts” (short for run command scripts), are used in both Linux and UNIX systems to start and stop services and perform various other tasks during system initialization.

The configuration file ‘/etc/inittab’ is used to control the behavior of the init process, defining which processes to start at specific runlevels and other system startup settings.

Syntax:

init [OPTIONS...] {COMMAND}

This syntax allows you to specify options and commands to control the system’s initialization process, including changing runlevels, rebooting, or shutting down the system.

Run Levels in Linux

Run Levels is the state of init where a group of processes is defined to start at the startup of OS. The process spawned by init for each of this run levels are defined in the file /etc/inittab. Each runlevel has a certain number of services stopped or started. Conventionally seven runlevel exist numbers from zero to six.

Standard Run Levels for Red Hat Based Distribution:

Runlevel

Mode Action
0 Halt Shuts down system
1 Single-User Mode

Does not configure network interfaces, start daemons, 

or allow non-root logins

2 Multi-User Mode Does not configure network interfaces or start daemons.
3 Multi-User Mode with Networking Starts the system normally.
4 Undefined Not used/User-definable
5 X11 As runlevel 3 + display manager(X)
6 Reboot Reboots the system

Detailed Explanation of Runlevels

  • Runlevel 0: Halt
    This runlevel stops all processes and shuts down the system. It is used when powering off the machine safely. 
  • Runlevel 1: Single-User Mode
    In this mode, the system boots into a single-user environment, usually for maintenance tasks. Networking is disabled, and only the root user can log in.
  • Runlevel 2: Multi-User Mode
    This runlevel supports multiple users but does not start networking services or daemons. It is often used for specific server setups that do not require network access.
  • Runlevel 3: Multi-User Mode with Networking
    Runlevel 3 is a fully operational state, supporting multiple users with all network services and daemons running. This is a common default runlevel for servers.
  • Runlevel 4: Undefined/User-Definable
    Runlevel 4 is generally unused by default but is available for custom user configurations. Administrators can define this runlevel to suit specific needs.
  • Runlevel 5: X11 (Graphical Interface)
    Similar to runlevel 3, but with the addition of the graphical display manager (X Window System). This runlevel is typically used for desktop systems.
  • Runlevel 6: Reboot
    Runlevel 6 restarts the system by rebooting. It is used when you need to restart all services or reinitialize the system completely.

Conclusion

The ‘init’ process is a fundamental component of the Linux operating system, responsible for initializing the system, managing services, and controlling the overall boot process. Through runlevels, it offers a structured way to manage system states, allowing administrators to customize which services run at various stages of the system’s lifecycle. Understanding and utilizing ‘init’ effectively can significantly enhance system performance, security, and reliability, making it an indispensable tool for Linux system administration.

init command in Linux – FAQs

What is the init process in Linux?

The ‘init’ process is the first process that starts when a Linux system boots up. It initializes the system, manages services, and controls the overall boot process, running until the system is shut down.

Why is the init process important?

‘init’ is crucial because it starts and manages all other processes on the system. It sets up the operating environment and ensures that necessary services and processes are running according to system requirements.

What are runlevels in Linux?

Runlevels are predefined states of the Linux system that define which services and processes are started or stopped. Each runlevel has a specific configuration, ranging from shutting down the system to full multi-user operation with a graphical interface.

How does init use runlevels?

The ‘init’ process uses runlevels to determine the state of the system and manage which services should be running. It reads the configuration from the ‘/etc/inittab’ file to decide which processes to start at each runlevel.

What are the standard runlevels in Red Hat-based distributions?

The standard runlevels are:

  • 0: Halt (Shuts down the system)
  • 1: Single-User Mode (Maintenance mode without networking)
  • 2: Multi-User Mode (No networking)
  • 3: Multi-User Mode with Networking
  • 4: Undefined/User-Definable
  • 5: X11 (Multi-User Mode with GUI)
  • 6: Reboot

    Previous Article
    Next Article

    Similar Reads

    What is init.d in Linux Service Management?
    In Linux there are several services that can be started and stopped manually in the system, some of their services are ssh, HTTP, tor, apache, etc. To start and run these services we used to simply type service "service name" start/stop/status/restart Example: service ssh start And to check if this service is running we type the command service ssh
    2 min read
    Systemd vs Init Cheatsheet for Linux
    Systemd is the new init framework, beginning with Fedora and presently embraced in numerous circulations like RedHat, Suse, and Centos. All things considered, the vast majority of us have been utilizing conventional SysV init scripts typically living in/and so on/rc.d/init.d/. These contents conjure a daemon parallel which will then, at that point,
    3 min read
    Ccat – Colorize Cat Command Output command in Linux with Examples
    ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
    2 min read
    How to Display Command History in Linux | history Command
    The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
    4 min read
    select command in Linux with examples
    select command in Linux is used to create a numbered menu from which a user can select an option. If the user enters a valid option then it executes the set of command written in select block and then ask again to enter a number, if a wrong option is entered it does nothing. If user enters nothing and simply press 'enter' the option menu gets print
    1 min read
    atrm command in Linux with examples
    atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
    1 min read
    expand Command in LINUX with examples
    Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
    3 min read
    rcp Command in Linux with examples
    There comes a time while using LINUX when there is a need to copy some information stored in a file to another computer. This can be done simply using rcp command line utility . Obviously there exists some other methods to complete the above mentioned task which are more secure (like scp or rsync) but this command lets you do this in the simple way
    4 min read
    fmt command in Linux with examples
    fmt command in LINUX actually works as a formatter for simplifying and optimizing text files. Formatting of text files can also be done manually, but it can be really time-consuming when it comes to large text files, this is where fmt comes to rescue. fmt re-formats each paragraph in the file specified, writing to standard output. Here's the syntax
    4 min read
    unexpand command in Linux with Examples
    To convert the leading spaces and tabs into tabs, there exists a command line utility called unexpand command. The unexpand command by default convert each spaces into tabs writing the produced output to the standard output. Here's the syntax of unexpand command : Syntax : $unexpand [OPTION]... [FILE]... where, OPTION refers to the options compatib
    2 min read
    anacron command in linux with examples
    anacron command is used to execute commands periodically with a frequency specified in days. Its main advantage over cron is that it can be used on a machine which is not running continuously. In cron if a machine is not running on time of a scheduled job then it will skip it, but anacron is a bit different as it first checks for timestamp of the j
    3 min read
    for command in Linux with Examples
    for command in Linux is used to repeatedly execute a set of command for every element present in the list. Syntax: for NAME [in WORDS ... ] ; do COMMANDS; done Example: Options: help for : It displays help information.
    1 min read
    autoheader command in Linux with Examples
    autoheader command in Linux is used to create a template file of C "#define" or any other template header for configure to use. If the user will give autoheader an argument, it reads the standard input instead of reading configure.ac and also writes the header file to the standard output. This command scans the configure.ac file and figures out whi
    1 min read
    expect command in Linux with Examples
    expect command or scripting language works with scripts that expect user inputs. It automates the task by providing inputs. // We can install expect command using following if not installed // On Ubuntu $sudo apt install expect // On Redhat based systems $ yum install expect First we write a script that will be needing inputs from users and then we
    2 min read
    function command in Linux with examples
    The function is a command in Linux that is used to create functions or methods. It is used to perform a specific task or a set of instructions. It allows users to create shortcuts for lengthy tasks making the command-line experience more efficient and convenient. The function can be created in the user's current shell session or saved in the shell
    2 min read
    fg command in Linux with examples
    fg command in linux used to put a background job in foreground. Syntax: fg [job_spec] job_spec may be: %n : Refer to job number n. %str : Refer to a job which was started by a command beginning with str. %?str : Refer to a job which was started by a command containing str. %% or %+ : Refer to the current job. fg and bg will operate on this job if n
    1 min read
    bg command in Linux with Examples
    bg command in linux is used to place foreground jobs in background. Syntax: bg [job_spec ...] job_spec may be: %n : Refer to job number n. %str : Refer to a job which was started by a command beginning with str. %?str : Refer to a job which was started by a command containing str. %% or %+ : Refer to the current job. fg and bg will operate on this
    1 min read
    Clear Command in Linux with Examples
    clear is a standard Unix computer operating system command that is used to clear the terminal screen. This command first looks for a terminal type in the environment and after that, it figures out the terminfo database for how to clear the screen. And this command will ignore any command-line parameters that may be present. Also, the clear command
    2 min read
    Continue Command in Linux with examples
    continue is a command which is used to skip the current iteration in for, while, and until loop. It is used in scripting languages and shell scripts to control the flow of executions. It takes one more parameter [N], if N is mentioned then it continues from the nth enclosing loop. The syntax for the `continue` command in Linuxcontinue or continue [
    2 min read
    hostid command in Linux with examples
    hostid is a command in Linux that is used to display the Host's ID in hexadecimal format. It provides a quick and straightforward way to retrieve the host ID, allowing administrators to associate it with software licenses or perform system-specific operations. Syntax of `hostid` command in Linuxhostid [OPTION] Options provided by hostedhostid --hel
    1 min read
    Dirname Command in Linux with Examples
    dirname is a command in Linux that is used to remove the trailing forward slashes "/" from the NAME and prints the remaining portion. If the argument NAME does not contain the forward slash "/" then it simply prints dot ".". In other words, we can say that the `dirname` command is a useful tool for extracting the directory portion from a given path
    2 min read
    sdiff command in Linux with Examples
    sdiff command in linux is used to compare two files and then writes the results to standard output in a side-by-side format. It displays each line of the two files with a series of spaces between them if the lines are identical. It displays greater than sign if the line only exists in the file specified by the File2 parameter, and a | (vertical bar
    2 min read
    factor command in Linux with examples
    The factor command in Linux is used to print the prime factors of the given numbers, either given from command line or read from standard input. The numbers given through standard input may be delimited by tabs, spaces or newlines. Syntax: factor [NUMBER] Factor 100 (non-prime number): We get the prime factors 2 and 5 that make up 100. Factor 13 (p
    1 min read
    chpasswd command in Linux with examples
    chpasswd command is used to change password although passwd command can also do same. But it changes the password of one user at a time so for multiple users chpasswd is used. Below figure shows the use of passwd command. Using passwd we are changing the password of the guest user. Here first you have to enter the password of the currently signed u
    2 min read
    dir command in Linux with examples
    dir command in Linux is used to list the contents of a directory. How is dir command different from ls? dir command differs from ls command in the format of listing contents that is in default listing options. By default, dir command lists the files and folders in columns, sorted vertically and special characters are represented by backslash escape
    3 min read
    eval command in Linux with Examples
    eval is a built-in Linux command which is used to execute arguments as a shell command. It combines arguments into a single string and uses it as an input to the shell and execute the commands. Syntax eval [arg ...] Example: In the below figure, you can see that cd Desktop command is stored in a variable "CD" as a shell command. Now you can use thi
    1 min read
    lsmod command in Linux with Examples
    lsmod command is used to display the status of modules in the Linux kernel. It results in a list of loaded modules. lsmod is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded. Syntax: lsmod Example: Run lsmod at the command line to list all active kernel modules. lsmod Output:
    1 min read
    emacs command in Linux with examples
    Introduction to Emacs Editor in Linux/Unix Systems: The Emacs is referred to a family of editors, which means it has many versions or flavors or iterations. The most commonly used version of Emacs editor is GNU Emacs and was created by Richard Stallman. The main difference between text editors like vi, vim, nano, and the Emacs is that is faster, po
    5 min read
    builtin command in Linux with examples
    builtin command is used to run a shell builtin, passing it arguments(args), and also to get the exit status. The main use of this command is to define a shell function having the same name as the shell builtin by keeping the functionality of the builtin within the function. Syntax: builtin [shell-builtin [arg ..]] Example: Here, we are creating a f
    1 min read
    dc command in Linux with examples
    dc command in Linux is used to evaluate arithmetic expressions. It evaluates expressions in the form of a postfix expression. Entering a number pushes it into the stack and entering an operator evaluates an expression and pushes the result back into the stack. It can evaluate +, -, /, *, %, ^. Different commands can be used to manipulate stack. Syn
    2 min read