Feel like starting over? This tutorial will show you how to cleanly and safely reboot or shut down your Linux or macOS computer from the command line.
We’re Going Down
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:
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
poweroff contain exactly the same information.
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.
systemd-based distributions the
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.
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
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!
The time string we used was
+15 , representing 15 minutes from now. The
+ is optional. We could have typed
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.
To cancel a shutdown, use the
-c (cancel) option.
Although you don’t get any notification that your shutdown has been canceled, your logged in users do get notified.
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.
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
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.
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.
-H(halt) option will take your computer down to the halt state but will not ask the hardware to power down.
-P(poweroff) is the default action . The computer is brought down to the halt state and is then powered off.
-r(reboot) option will take your computer down to the halt state and then restart it.
-h(halt and poweroff) option is the same as
-P. If you use
-Hoption takes priority.
-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
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
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,
poweroff will probably meet your needs.
|Files||tar · pv · cat · tac · chmod · grep · diff · sed · ar · man · pushd · popd · fsck · testdisk · seq · fd · pandoc · cd · $PATH · awk · join · jq · fold · uniq · journalctl · tail · stat · ls · fstab · echo · less · chgrp · chown · rev · look · strings · type · rename · zip · unzip · mount · umount · install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · vi · nano · mkdir · du · ln · patch · convert · rclone · shred · srm|
|Processes||alias · screen · top · nice · renice · progress · strace · systemd · tmux · chsh · history · at · batch · free · which · dmesg · chfn · usermod · ps · chroot · xargs · tty · pinky · lsof · vmstat · timeout · wall · yes · kill · sleep · sudo · su · time · groupadd · usermod · groups · lshw · shutdown · reboot · halt · poweroff · passwd · lscpu · crontab · date · bg · fg|
|Networking||netstat · ping · traceroute · ip · ss · whois · fail2ban · bmon · dig · finger · nmap · ftp · curl · wget · who · whoami · w · iptables · ssh-keygen · ufw|
- › How to Turn Off an Ubuntu PC
- › How to Solve the “Too Many Open Files” Error on Linux
- › How to Install Arch Linux on a PC
- › How to Restart a Computer
- › 37 Important Linux Commands You Should Know
- › How to Set the Default Gateway in Linux
- › How to Move Your Linux home Directory to Another Drive
- › What Is HTTP?