Open
Close

Reboot debian from the console. Shutdown Linux from the command line. Shutdown Linux using poweroff

Let's look at how to restart or shut down your computer from the command line. I use this when, when installing some driver or under heavy load on the processor, the interface stops responding to my actions (although this happens extremely rarely). It is possible to kill a "gluttonous" process through the command line, but it is not always known which process it is, so a quick solution is to restart the computer.

Reboot the computer

I do this. I go to the console by pressing the keyboard shortcut Ctrl+Alt+F1. In the console, you must first enter your username and password (no characters are displayed when entering a password). And I run the command:

Sudo reboot

You will again need to enter the administrator password and press Enter. The computer will begin to restart.

You can also use the command to restart your computer shutdown, for this you need to use the key -r:

Sudo shutdown -r now

Turn off the computer

To shut down the computer from the command line, you need to run the command:

Sudo shutdown -h now

You can also shut down your computer by running the command:

Sudo halt

And also can be used.

Let's look at how to restart or shut down your computer from the command line. I use this when, when installing some driver or under heavy load on the processor, the interface stops responding to my actions (although this happens extremely rarely). It is possible to kill a "gluttonous" process through the command line, but it is not always known which process it is, so a quick solution is to restart the computer.

From time to time, you need to remotely reboot or shutdown your Linux operating system from the command line. This can be done in various ways, and we will consider them.

All the commands listed below must be executed as the root user.

Options set the shutdown parameters, we will look at them below. Time can be set in hh:mm format in 24 hour format. You can also use the +minutes entry, indicating how many minutes from the current moment you need to turn off your Linux computer. In addition, the now constant is available, indicating that you need to turn it off right now. shutdown command, with source -h.

As you can see, the usual shutdown is used, and the time constant now, that is, now. Now let's try to schedule the Linux computer to shut down in five minutes:

sudo shutdown -h +5 "The PC will be shut down in 5 minutes"

To shut down the system, use the halt and poweroff commands. The initial command shuts down the system but does not turn off the system's power. You will see a "System is halted" message indicating that you can turn off the power. This command is intended for older computers that do not support advanced power management. The second (poweroff) shuts down the system ( a set of elements that are in relationships and connections with each other, which forms a certain integrity, unity) and turns off its power.

Shutting down Linux using halt

The command is identical to the reboot command in its actions, the difference is that the halt command turns off the system. You can also turn off the computer by running the command:

Using halt may damage the system!

This command also turns off the computer. She just does it in her own unique way. It does not perform any preparatory actions before shutting down, but simply turns off the power.

Shutdown Linux using poweroff

The poweroff command is similar to the halt command, except that after stopping the system, a special request is sent to the feeding control system to turn off power, which allows you to turn off systems remotely. You can also use:

Shutdown Linux using telinit 0

Using this command, you can tell the init daemon to go to a certain execution level, namely the number 0 indicates that you need to go to the 0th level (system stop). The telinit crew does not support setting pauses and warning messages. Typically used when testing changes made to the inittab file.

Shut down Linux from the command line without sudo

Possible via dbus and ConsoleKit. It can be controlled via dbus. Only now it seems to be cut out everywhere.

ConsoleKit is a daemon that serves user sessions.

If you have systemd, then hocus pocus won't work. Maybe experts will drop by and tell you how to do this via logind.

dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop

That's all, the discussion of the basic ways to shutdown and reboot Linux systems from the command line is completed. Now you know everything you need to know about how to shut down Linux through the terminal. If you're caught off guard by a typo or your computer freezes, you know what to do.

Turning off the computer is an action that ordinary users encounter almost every day. If you have to turn off the server quite rarely, then ordinary desktop computers are subject to this operation very often. Most users turn off Linux in the system's GUI. In the KDE desktop environment this is done through the main menu, and in Gnome and Unity there is even a special toolbar button for this task.

But it is not always possible to turn off a Linux computer this way. For example, if the desktop environment is not working, then there is nothing left to do except shut down the computer from the command line. In addition, shutting down a Linux computer through the terminal is the only possible way for servers that do not have a graphical interface. As you'll see, this method is also much more flexible than a regular shutdown, since you can set the shutdown time you want, or shut down the computer while waiting for a specific program to complete.

To shut down a Linux computer, use the shutdown command. There are also poweroff and halt commands, but they are for non-standard cases. Usually, just shutdown is enough. You can also turn off Linux from the console using the SysRq keyboard shortcuts. But first, let's look at the syntax of the shutdown command.

The command syntax is very simple:

$ shutdown [options] [time] [message]

Options set the shutdown parameters, we will look at them below. Time can be set in hh:mm format in 24 hour format. You can also use the +minutes entry, indicating how many minutes from the current moment you need to turn off your Linux computer. The now constant is also available, indicating that you need to turn it off right now.

The message parameter allows you to specify a message that will be displayed in the terminal before shutdown.

Options

  • --help- display help about the program
  • -H, --halt- turn off power without killing processes or remounting file systems
  • -P, --poweroff- normal shutdown
  • -k- do not perform real actions, but only display a message
  • --no-wall- turn off the computer, but do not display a message
  • -c- cancel scheduled shutdown of linux from command line

That’s basically all the options of the utility; there are more than enough of them for such a simple action. Now we can move on to the examples, but first let's look at what happens when Linux is turned on.

Linux shutdown process

Naturally, the shutdown linux command or any other does not automatically shut down the system and turn off the computer. It simply passes the shutdown request to the init system and then to the kernel. And they already perform a number of complex operations to prepare and turn off the computer. In short, here they are:

  • Ending user processes
  • Signal SIGTERM to all processes
  • SIGKILL signal to all processes
  • Mounting file systems in read-only mode
  • Preparing external devices for shutdown
  • User space locking to ensure that no user code is ever run again
  • Shutdown and power off most peripheral devices
  • Turning off the computer's power

Now you understand the essence of the shutdown process and why you can’t just unplug the power cord from the outlet. If you do this, the computer will turn off instantly and will not perform all necessary operations, and this may result in the loss of unsaved or even recently saved data, damage to the file system, etc. Therefore, it is advisable to turn off the computer correctly using shutdown or other special utilities.

Now let's move on to examples.

Shutting down your computer in Linux

1. shutdown

The simplest and most commonly used linux computer shutdown command will shut down the computer immediately:

sudo shutdown -h now

As you can see, the usual shutdown is used, and the time constant now, that is, now.

Now let's try to schedule the Linux computer to shut down after five minutes:

sudo shutdown -h +5 "The computer will shut down in 5 minutes"

We scheduled a message to appear before shutting down.

Now let's cancel the shutdown of the Linux computer:

sudo shutdown -c

In the same way, we can specify the exact shutdown time, for example at nine in the evening:

sudo shutdown -h 21:00

As I already said, not only the shutdown linux command can shut down the computer, there are several other utilities that can do this. Let's consider them too.

2. reboot

The reboot command is usually used to reboot the system, but it can also shut down the computer. We will not consider it in detail, because it is even simpler than the shutdown command. To turn it off, you need to specify the -p option:

3.halt

This command also turns off the computer. She just does it in her own unique way. It does not perform any preparatory steps before shutting down, but simply turns off the power:

Using halt may damage the system

4.poweroff

This is analogous to halt, doing exactly the same thing:

5. SysRq

Remember at the beginning of the article, I talked about the keyboard shortcut to turn on the computer? Let's consider this issue in more detail.

SysRq is a subsystem implemented at the kernel level. The kernel processes all keystrokes, and with the help of this subsystem, it can accept commands from the user even when the system is completely frozen. The main purpose of this subsystem is to work with the computer in problematic situations, for example, if you think that your computer has been infected by a virus, or the computer has frozen and needs to be turned off. Keyboard shortcuts are used to access SysRq Alt+PrtScr+number

The most interesting thing is that we can safely shutdown a Linux computer. To do this, hold down the Alt + PrtScr keys and press alternately:

  • R- unlock keyboard
  • E- send a SIGTERM signal to all processes
  • I- send a SIGKILL signal to all processes
  • S- transfer all data from the file system cache to disk
  • U- remount read-only file systems
  • B- reboot

You can also use the keyboard shortcut instead of all this Alt+PrtScr+O, in this case, the entire procedure will be performed automatically; this command is not supported by all kernels.

conclusions

Now you know everything you need to know about how to shut down Linux through the terminal. If you are caught off guard by an error or your computer freezes, you know what to do. If you have any questions, write in the comments!

Problem
Just look at how many ways there are to shutdown and reboot: shutdown, halt, init 0, poweroff, Ctrl+Alt+Delete... Which one is better to use?
Solution
The choice is not that significant; use the method that suits you best. The following shutdown commands can only be used by the root user:
# shutdown -h now
or
#poweroff
or
#halt
Shutdown after six minutes:
# shutdown -h +6
The shutdown command sends alerts to all connected users.
You can specify your own text:
# shutdown -h +6 "Time to stop working and start partying."
Console users will see the following message:
Broadcast message from root (pts/6) Wed Aug 14 13:51:24 2003
Time to stop working and start partying.
The system is going DOWN for system halt on 6 minutes!
To cancel shutting down your computer, run the following command
with root rights:
# shutdown -с
The reboot is performed with the command
# shutdown -r now
or
# reboot
or by pressing Ctrl+Alt+Delete. Any user can reboot the computer unless you disable this feature in /etc/inittab (Section 7.11 describes how to disable reboots or grant permission to specific users).
A comment
Remember that the shutdown process must always be controlled. Everyone
computers, including machines running Linux, have to do
a considerable amount of work so that the power can be turned off safely. The system must shut down services, unmount file systems, and flush buffers to disk.
The shutdown, poweroff and halt commands can only be executed by privileged people
user root. The restriction looks pretty stupid, because anyone
The window manager and desktop environment have their own shutdown menu, and anyone in the vicinity of the computer can press the power button. But such is life, and you have to come to terms with it.
A possible solution is to grant limited privileges to execute shutdown commands with sudo. Another solution is based on creating a special group of users who are allowed to shut down.
see also
shutdown(8), poweroff(8); section 8.20; Section 8.21.

The shutdown command in Linux allows you to shutdown, reboot, or schedule your system to shutdown. This article explains the most common and useful examples of the shutdown command in Linux.

shutdown command syntax

Before we see the usage of the shutdown command, let's first look at its syntax. shutdown
  • options: you can specify whether you want to stop, power off, restart, etc.
  • time: you can specify when to shutdown
  • message: you can send a custom message to all registered users

Note

The shutdown command requires superuser privileges. Therefore, you must either be root or run the command with sudo.

5 Practical Examples of the Shudown Command in Linux

Now that you know the syntax of the shutdown command, let's see how to use it.

If you simply use the shutdown command, it will begin the shutdown process after one minute. Therefore, remember that the default time interval for the shutdown command is one minute.

Sudo shutdown Shutdown scheduled for Mon 2018-11-19 23:46:21 UTC, use "shutdown -c" to cancel.

Unsuspecting Linux users expect the shutdown command to shut down the system immediately, but when they see a message such as a UTC timestamp, they are often confused.

1. Immediate system shutdown.

You don't always have to wait a minute for the system to turn off. You can shut down your system immediately by specifying a scheduled time +0 or now .

Sudo shutdown now

2. Schedule system shutdown

You can schedule a stop in the future by specifying a time argument in either +t or hh:mm format.

For example, if you want to shut down the system after 20 minutes, you can use this command:

Sudo shutdown +20

If you want to shut down the system at 3pm, you can use it like this:

Sudo shutdown 15:00

Needless to say, the reference time and time zone are system time.

Note

Five minutes before the scheduled shutdown time, the system will not allow login activity. This means that a new user cannot log in for five minutes after a scheduled shutdown.

3. Reboot the system with the shutdown command

There is a separate reboot command, but you don't need to learn a new command just to reboot the system. You can use the shutdown command in Linux to reboot.

To reboot the system using the shutdown command, use the -r option.

Sudo shutdown -r

The behavior is the same as the normal shutdown command. It's simple that instead of shutting down the system, it will restart.

So, if you used shutdown -r without any time arguments, it would reboot after one minute.

You can schedule a reboot in the same way as a shutdown.

Sudo shutdown -r +45

You can also immediately reboot the system with the shutdown command:

Sudo shutdown -r now

4. Transmit custom message

If you are working in a multi-user environment and there are multiple users logging on, you can send them your own broadcast message with the shutdown command.

By default, all registered users will receive a notification about the scheduled outage and the time. You can set up a broadcast message in the shutdown command itself:

Sudo shutdown 15:00 "The system will be shut down for a hardware update, please save your work"

You can use the shutdown command with the -k option to initiate a "fake shutdown". It will not shut down the system, but a broadcast message will be sent to all registered users.

5. Cancel scheduled shutdown

If you've planned a shutdown, you don't have to live with it. You can always cancel the shutdown using the -c option.

Sudo shutdown -c

And if you have communicated the scheduled shutdown message, like a good system administrator, you can also notify other users to cancel the scheduled shutdown.

Sudo shutdown -c "scheduled shutdown was cancelled"

Halt vs Power off

Halt (option -H): kills all processes and shuts down the CPU,
Power off (option -P): Very similar to stop, but also turns off the block itself.

Historically, computers used to be used to shut down the system and then print a message like "shut down now normally" and then the computers were shut down using physical switches.

These days, termination should automatically power down the system thanks to ACPI support.

These were the most common and most useful examples of the shutdown command in Linux. I hope you learned how to shutdown Linux system via .

If you have any questions or suggestions, feel free to let us know in the comments section.