How to Use the `reboot` Command (with examples)

How to Use the `reboot` Command (with examples)

The reboot command is a powerful tool that allows you to reboot or power off your system. In this article, we will explore different use cases of the reboot command, along with the corresponding code examples and explanations.

Example 1: Reboot the system

Code:

reboot

Motivation: Sometimes, you may need to reboot your system to apply changes or troubleshoot issues. The reboot command is the simplest way to achieve this.

Explanation: By executing the reboot command, you effectively instruct your system to restart. The command sends a signal to the kernel, which then proceeds with a clean shutdown of all processes before rebooting the machine.

Example Output:

Broadcast message from root@localhost
(unknown) at 14:30 ...
The system is going down for reboot NOW!

Example 2: Power off the system (same as poweroff)

Code:

reboot --poweroff

Motivation: In certain scenarios, you may want to power off the system completely instead of just rebooting it. The --poweroff option of the reboot command allows you to achieve this.

Explanation: By appending the --poweroff option to the reboot command, you instruct the system to perform a complete shutdown instead of a reboot. This is equivalent to using the poweroff command separately.

Example Output:

Broadcast message from root@localhost
(unknown) at 14:35 ...
The system is going down for power off NOW!

Example 3: Halt (terminates all processes and shuts down the CPU) the system (same as halt)

Code:

reboot --halt

Motivation: In some situations, you may want to halt the system instead of rebooting or powering it off. The --halt option of the reboot command allows you to instantly terminate all processes and shutdown the CPU.

Explanation: By appending the --halt option to the reboot command, you instruct the system to halt all processes. This is equivalent to using the halt command separately.

Example Output:

Broadcast message from root@localhost
(unknown) at 14:40 ...
The system is going down for halt NOW!

Example 4: Reboot immediately without contacting the system manager

Code:

reboot --force

Motivation: There may be situations where you need to force an immediate reboot without involving the system manager. The --force option of the reboot command enables you to achieve this.

Explanation: By using the --force option with the reboot command, you bypass any checks or delays typically performed by the system manager. This can be useful when troubleshooting or handling critical situations.

Example Output:

Broadcast message from root@localhost
(unknown) at 14:45 ...
The system is going down for reboot NOW!

Example 5: Write the wtmp shutdown entry without rebooting the system

Code:

reboot --wtmp-only

Motivation: In some cases, you may only need to update the wtmp file but not actually reboot the system. The --wtmp-only option of the reboot command allows you to achieve this without performing a full reboot.

Explanation: The --wtmp-only option instructs the reboot command to update the wtmp file, which logs system shutdown and reboot events, without actually rebooting the system. This can be useful when you want to record a system shutdown without interrupting ongoing processes.

Example Output:

Broadcast message from root@localhost
(unknown) at 14:50 ...
The system is going down for system halt NOW!

Conclusion

The reboot command provides various options and functionalities for managing system reboots and shutdowns. By familiarizing yourself with these use cases and their corresponding code examples, you can effectively control the reboot and power-off behavior of your system.

Related Posts

How to use the command 'ipcs' (with examples)

How to use the command 'ipcs' (with examples)

The ‘ipcs’ command is used to display information about resources used in IPC (Inter-process Communication).

Read More
Using the make command (with examples)

Using the make command (with examples)

Calling the first target specified in the Makefile make Motivation: This use case is helpful when you want to compile the entire project or perform all the tasks specified in the Makefile.

Read More
Using Git Secret (with examples)

Using Git Secret (with examples)

1: Initializing git-secret in a local repository git secret init Motivation: The git secret init command initializes git-secret in a local repository.

Read More