How to start or stop Linux from the command line

Do you want to start over? This tutorial will show you how to cleanly and safely restart or shut down your Linux or macOS computer from the command line.

We’re going down

Sometimes all you need to do is reboot or do a full shutdown. If you are on a server without a GUI or in an SSH session with a remote computer, the command line is your only option. Linux and Unix-like systems like macOS offer several commands to shut down or restart your system right from the command line.

The commands you can use are:

  • switch off
  • start anew
  • Stop
  • switch off

Searching the man pages for these commands can be confusing. Depending on which command line options you choose, all of these commands can be executed Shutdowns , Restarts and system stops. In fact, the man pages for reboot , halt , and poweroff contain exactly the same information .

What’s behind it?

The answer lies in that system Bootstrap System that 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 many distributions. Debian and Ubuntu swapped too systemd in 2015.

on systemd -based distributions the shutdown , reboot , halt , and poweroff Commands are practically abbreviations that point to the systemctl Command. Keeping these commands provides some level of compatibility with System V init -based distributions. That means shell scripts (and tough System V system administrators) won’t be upset when moved to a computer with one systemd Distribution runs on it.

Use shutdown

Shutting down or restarting a multi-user system means you need to plan ahead. You have to decide when to shut down or restart, and warn the other system users when and when the shutdown is coming. When it’s your own computer and you’re the only one using it, life is a lot easier.

To run any of these commands, you’ll need to be in the sudo Group. That is, you must have superuser privileges and be able to use the sudo Command. If the command you issued takes effect immediately and has no effect on other logged-in users, you do not need to use sudo . If you try to use any of these commands and the command is rejected, try again sudo .

The default is shutdown The command ensures that all processes have been stopped properly, all file systems have been synchronized and all CPU activities have stopped. This is the ‘halt’ state. It then sends a message to the hardware to interrupt the power supply. This is of course the shutdown or “poweroff” state.

It is common to happen shutdown some parameters, like a time string and a message sent to the logged in users to warn them about shutdown. Let’s plan a shutdown for 15 minutes from now on. Type shutdown , a space, +15 , a space, and then the message to be sent to the users.

                      shutdown +15 Shutting down in 15 minutes!

Shutdown command +15 message

The time string we used was +15 which is 15 minutes from now. the + it’s optional. We could have typed 15 .

We received a response confirming that a shutdown is planned and when it will take place. Registered users will receive the message we have provided.

Shutdown notification

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

                      shutdown -c

Shutdown -c cancel command

Although you won’t receive a notification that your shutdown has been canceled, your signed-in users will be notified.

Right of withdrawal

If you don’t specify a time string, a shutdown is scheduled for one minute from now on. Note that if you do not provide a time string, you will not be able to send a message to your logged-in users.


Shutdown command no parameters

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

switch off now

The time string can be a fixed time, e.g. B. 23:00. It must follow the format of HH:MM and must be in 24-hour format. New logins are prevented five minutes before the system failure.

Shutdown 23:00 with message

We know the standard action from shutdown puts the computer in the halt state and then in the off state. We can override this behavior by giving it other command line options.

  • the -H The (halt) option puts your computer in a halt state, but does not prompt the hardware to shut down.
  • the -P (Turn off) is the standard action. The computer is put on hold and then switched off.
  • the -r (Restart) will stop your computer and then restart it.
  • the -h (Hold and Power Off) option is the same as -P . When you use -h and -H together that -H Option takes precedence.
  • the -c The (Cancel) option cancels any scheduled shutdown, suspension or restart.

Here is a example where we have planned a restart.

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

Shutdown schedule a restart

The commands reboot, halt and poweroff

These commands perform the action their name suggests. However, each of them accept command line options for each of them to restart, stop, or power off. But why mix things up? These commands are best used at face value.

If you want to restart now, use reboot . If you want to turn off the device now, use poweroff , and if you want to stop the system now, use halt .




These commands take effect immediately. If any of these commands are denied, precede them sudo . Note, however, that a denial is usually due to other users being logged into the system you are trying to take offline.

Which command is right for me?

In multi-user environments with shutdown When you perform these actions, you have more control. The ability to schedule shutdowns and restarts, and to warn users with a broadcast message, is invaluable in these cases. For a single user computer, reboot and poweroff will likely meet your requirements.

Linux commands
Files tar · pv · cat · tac · chmod · grep · difference · sed · With · man · pushed · popd · fsck · Test disk · seq · fd · pandoc · CD · $ PATH · awk · join · jq · wrinkles · unique · Journalctl · tail · stat · ls · fstab · echo · fewer · chgrp · chown · rev · look · Strings · Type · rename · Postal code · unzip · assemble · ummount · To install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · weather · Nano · mkdir · from · ln · Patch · Convert · rclon · Scraps · srm
Processes alias · screen · above · kind · renice · progress · strace · system · tmux · chsh · story · at · Batch · for free · which · dmesg · chfn · User mod · ps · chroot · xargs · tty · pinkie finger · lsof · vmstat · Time out · Wall · Yes sir · kill · sleep · sudo · it is · Time · groupadd · User mod · groups · lshw · switch off · start anew · Stop · switch off · passwd · lscpu · crontab · date · bg · fg
Networking netstat · Ring · Trace route · ip · ss · who is · fail2ban · bmon · she · finger · nmap · ftp · curl · wget · who · who am I · w · iptables · ssh-keygen · ufw

Best Linux Laptops for Developers and Enthusiasts

Related Posts