poweroff Command in Linux


The poweroff command in Linux shuts down the Linux system. It safely shuts down and turns off a Linux system. It ensures that all running processes are terminated, file systems are synced, and hardware is properly powered down to prevent data loss or corruption. Note that running poweroff without sudo may result in a permission error.

Table of Contents

Here is a comprehensive guide to the options available with the poweroff command −

Syntax of poweroff Command

The syntax of the poweroff command in Linux is as follows −

poweroff [options]

The [options] field in the above syntax is used to specify various options to change the command's behavior, such as displaying help, syncing storage media before shutting down, and others.

poweroff Command Options

The options for the poweroff command are listed below −

FlagsOptionsDescription
--haltHalts the system.
--rebootReboots the system.
-f--forceForces an immediate shutdown, halt, or reboot without notifying the init system.
-w--wtmp-onlyLogs a shutdown entry in wtmp without actually shutting down.
-d--no-wtmpPrevents logging a shutdown entry in wtmp.
-n--no-syncSkips syncing disks before shutdown, reboot, or halt.
--no-wallSuppresses the broadcast message before shutdown, reboot, or halt.
--helpDisplays a brief help message and exits.

Examples of poweroff Command in Linux

In this section, the usage of the poweroff command in Linux will be discussed with examples.

  • Shutting Down the System
  • Force Shutting Down the System
  • Halting the System
  • Rebooting the System
  • Logging the Shutdown without Powering Off
  • Skipping Disk Sync before Shutting Down
  • Suppressing Broadcast Messages before Shutting Down
  • Displaying Usage Help

Shutting Down the System

To shut down and power off the Linux system, execute the poweroff command with the sudo privileges −

sudo poweroff

Force Shutting Down the System

To immediately and force shut down the Linux system, use the -f or --force option with the poweroff command −

sudo poweroff -f

Note: The above command forces an immediate shutdown without properly unmounting file systems.

Halting the System

To halt a Linux system, use the --halt option −

sudo poweroff --halt

Halt stops the OS and CPU but may leave power on, whereas poweroff shuts down the OS and completely turns off the system.

Rebooting the System

To reboot the Linux system, use the --reboot option with the poweroff command −

sudo poweroff --reboot

Reboot restarts the system by shutting it down and then powering it back on. It is equivalent to a full system restart.

Logging the Shutdown without Powering Off

To log the shutdown entry in the system logs without turning off the machine use the -w or --wtmp-only option −

sudo poweroff -w
poweroff Command in Linux1

This command can be useful for testing shutdown logging or for recording a planned shutdown event without actually turning off the system. To check the log, use the following command −

last -x shutdown reboot
poweroff Command in Linux2

Skipping Disk Sync before Shutting Down

To skip the hard disk sync before shutting down, halt, or reboot, use the -n or --no-sync option −

sudo poweroff -n

Note that skipping disk synchronization may result in unsaved data or filesystem corruption

Suppressing Broadcast Messages before Shutting Down

By default, the poweroff command sends a broadcast message about the system shut down to all logged-in users. To suppress this message, use the --no-wall option:

sudo poweroff --no-wall

Displaying Usage Help

To display the usage help of the poweroff command, use the --help option −

poweroff --help

Conclusion

The poweroff command in Linux safely shuts down the system, ensuring processes terminate properly and hardware is powered down correctly. Various options allow you to customize the behavior, such as forcing shutdowns, halting, rebooting, or just logging shutdown events.

Using poweroff without sudo may result in a permission error. Care should be taken when using force shutdown or skipping disk sync, as they may cause data loss.

In this tutorial, we covered the poweroff command, its syntax, options, and usage in Linux with examples.