Sat. Sep 23rd, 2023

Key Takeaways

  • Linux and macOS systems provide commands such as shutdown, reboot, halt, and poweroff to safely shut down or restart your computer from the command line.
  • The commands are shortcuts that point to the systemctl command in systemd-based distributions, ensuring compatibility with System V init-based systems.
  • By using the shutdown command, you can schedule shutdowns or reboots, provide messages to logged-in users, and cancel scheduled actions using command line options.

Feel like starting over? We’ll show you how to cleanly and safely reboot or shut down your Linux or macOS computer from the command line.

What Shutdown Commands Are There on Linux?

Sometimes you just have to go for the reboot or the total shutdown. If you’re working on a GUI-less server or you’re on an SSH session to a remote computer, the command line is your only option. Linux and Unix-like systems such as macOS provide several commands to shutdown or reboot your system right from the command line.

The commands you can use are:

  • shutdown
  • reboot
  • halt
  • poweroff

Looking through the man pages for these commands can be confusing. Depending on which command line options you choose, all of these commands can perform shutdowns, reboots, and system halts. In fact, the man pages for reboot, halt, and poweroff contain exactly the same information.

man page for halt command

What’s Behind This?

The answer lies in the systemd bootstrap system which replaced the venerable System V init system. In the Linux world, Fedora started to use systemd in 2011. Since then it has been adopted by a great many distributions. Debian and Ubuntu swapped to systemd in 2015.

On systemd -based distributions the shutdown, reboot, halt, and poweroff commands are effectively shortcuts that point to the systemctl command. Retaining these commands provides a degree of compatibility with System V init -based distributions. It means shell scripts (and hard core System V system administrators) don’t keel over if they are moved to a computer with a systemd distribution running on it.

Using Shutdown on Linux

Shutting down or rebooting a multi-user system means you have to plan ahead. You need to decide when you’re going to go for the shutdown or reboot, and warn the other system users the shutdown is coming, and when. If it is your own computer and you’re the only one who uses it, life is much simpler.

To run any of these commands you have to be in the sudo group. That is, you must have superuser permissions and be able to use the sudo command. If the command you have issued is going to take effect immediately and will not affect other logged in users, you will not need to use sudo. If you try to use one of these commands and the command is refused, re-try with sudo .

By default the shutdown command ensures that all processes are stopped cleanly, all filesystems are synced, and all CPU activity has ceased. This is the ‘halt’ state. It then sends a message to the hardware to cut off power. This, of course, is the shutdown or “poweroff” state.

It is common to pass shutdown some parameters, such as a time string and a message that will be sent to the logged in users to warn them off the shutdown. Let’s schedule a shutdown for 15 minutes from now. Type shutdown , a space, +15, a space, and then the message to send to the users.

shutdown +15 Shutting down in 15 minutes!

shutdown command +15 message

The time string we used was +15 , representing 15 minutes from now. The + is optional. We could have typed 15.

We get a response that confirms a shutdown is scheduled and when it will occur. Logged in users will receive the message that we provided.

shutdown notification

To cancel a shutdown, use the -c (cancel) option.

shutdown -c

Shutdown -c cancel command

Although you don’t get any notification that your shutdown has been canceled, your logged in users do get notified.

Cancellation notice

If you don’t provide a time string a shutdown will be scheduled for one minute from now. Note that you can’t provide a message to your logged in users if you don’t specify a time string.


shutdown command no paramters

If you can’t even wait a minute, you can use now as the time string and the shutdown takes immediate effect. Using now is like using +0.

shutdown now

The time string can be a set time, such as 23:00. It must follow the format of HH:MM and must be in the 24-hour clock. Five minutes before the system goes down new logins are prevented.

shutdown 23:00 with message

We know the default action of shutdown makes the computer go down to the halt state and then into the powered off state. We can override this behavior by passing other command line options to it.

  • The -H (halt) option will take your computer down to the halt state but will not ask the hardware to power down.
  • The -P (poweroff) is the default action . The computer is brought down to the halt state and is then powered off.
  • The -r (reboot) option will take your computer down to the halt state and then restart it.
  • The -h (halt and poweroff) option is the same as -P. If you use -h and -H together, the -H option takes priority.
  • The -c (cancel) option will cancel any scheduled shutdown, halt or reboot.

Here’s an example where we have scheduled a reboot.

shutdown -r 08:20 System rebooting at 08:20

shutdown scheduling a reboot

The reboot, halt and poweroff Commands

These commands perform the action their name suggests. However, each of them will accept command line options to make any one of them perform a reboot, a halt, or a poweroff. But why confuse matters? These commands are best used at face value.

If you want to reboot now, use reboot . If you want to poweroff now, use poweroff, and if you want halt the system now, use halt.


reboot command in a terminal window


halt command in a terminal window


poweroff command in a terminal window

These commands take immediate effect. If any of these commands are refused, precede them with sudo. But be aware, a refusal is usually because there are other users logged into the system that you’re about to take offline.

Which Command is Right For Me?

In multi-user environments using shutdown to perform these actions gives you more control. The facility to schedule shutdowns and reboots, and to alert users with a broadcast message will be invaluable in these cases. For a single-user computer, reboot and poweroff will probably meet your needs.

Source link

By John P.

Leave a Reply

Your email address will not be published. Required fields are marked *