None operating system not perfect. Even so, there may be driver and application issues. Linux is no exception. While it is more stable than Windows, there will probably come a time when you need to reboot your Linux computer.

But how could you do this? Several commands are available to shutdown or restart a Linux computer through the terminal.

Let's take a look at them in turn and see how and when to use these commands.

1. Disconnection

If you are done with Linux, the solution is to simply disable it, you can use the command syntax to do this:

shutdown

For example, to shut down your computer immediately, you would use:

Where -h means stop, and now- now, which means the instruction must be executed immediately. Various delays can be used. For example, you can use instead +5 to tell the computer to shutdown in five minutes.

If you want to use message(message), it will flash to all registered users:

shutdown -h +5 "Server is shutting down, save your work and log off."

Remember that you can find a complete list of switches for these commands by typing:

Restart with -r

An alternative option is to use the command -r to restart your computer. It is used instead of -h so, to restart your computer or server, you can use:

shutdown -r +5 "Server reboots in five minutes, save your work and log off."

Any scheduled shutdown or restart can be canceled by entering the command -c:

2. Reboot

Since the shutdown command has a restart option, it is not surprising that the reboot command has a shutdown option.

Standard reboot command:

This will prompt your computer to turn off and on again. However, if you want to turn off the device, the key -p will work:

Another option is a forced reboot. This can be useful if an application or service is frozen and you need to reboot quickly:

This command will force restart your Linux PC.

3. Stop

We've already seen the switch -h above, but stop can be used as a command by itself. This will shutdown the computer immediately with a simple four letter word:

Switch -f can also be used intermittently, but the results are inconsistent and may lead to system stability issues.

4. Poweroff

You may prefer the command terminology poweroff... This does the same as halt, except that it takes twice as long to enter text.

However, apart from using -f to forcibly turn off the power, you can also use the key -w to register a system reboot call in / var / log / wtmp... It is a potentially useful debugging tool like -verbose which can help with shutdown problems.

poweroff --verbose

5. Emergency option: REISUB

All of the above commands can be used in situations where the system works without problems. But what if the computer or server freezes and cannot be rebooted in an acceptable way?

The answer then is a keyboard combination. If you've switched from Windows, you probably know that Ctrl + Alt + Del displays a menu with shutdown as an option. If you hold it for longer, the machine will turn off automatically. In the meantime, on a Mac, you just have to hold down the power button (an option that also works on Windows hardware).

On Linux, the keyboard shortcut for reboot is Alt + Print screen+ B... However, if that doesn't work, or if there is a more complex problem, you can change the combination using up to six keys.

This is known as REISUB, due to the following forced abbreviation:

  • un R aw - Returns keyboard control back from the X display server.
  • t E rminate - Send the SIGTERM terminate signal to all processes to terminate gracefully.
  • k I ll - As above, but with a SIGKILL signal that causes processes to terminate immediately.
  • S ync - Flushes data to disk.
  • U nmount - remount everything file systems in read-only state.
  • re B oot - which is to be expected.

For this to work, you must hold Alt + Print Screen, and then, alternately press the keys: R E I S U B, in the same order. The delay between each press should be 1-2 seconds. This is necessary in order to give a little time to complete all of the above processes. Please note that this method does not usually work on ARM computers.

Help, I accidentally shut down my Linux computer or server!

We have seen how to undo a shutdown or restart command. However, there are times when you run a shutdown command while a vital process is running, especially on a remote server. You can work around this by setting molly-guard which can override the shutdown by checking certain parameters.

For example, there is a script that checks for SSH sessions. If you send a reboot, stop or shutdown command, molly-guard will require the name of the host you are about to shut down.

To do this, install molly-guard in the terminal:

sudo apt-get install molly-guard

Since molly-guard is running in the background, it will detect a command like poweroff, and will report that an SSH session has been detected. Then you can enter the hostname of the server to confirm shutdown or press Ctrl + C to cancel. Healthy!

These five ways to shutdown your Linux computer from command line especially useful as they can be used on the computer itself or over remote SSH. Since these commands are very concise, they are suitable for quick use - which can lead to accidental reboots from time to time! Fortunately, molly-guard is sufficient to avoid this.

To learn more about, check out our reference table.

Then SysRq can help out in the most seemingly hopeless situations, unless, of course, the kernel is in a "panic", as is usually evidenced by chaotically blinking keyboard LEDs. Interesting? Then read on.

The SysRq key appeared long before Windows started taking screenshots. IBM originally intended the SysRq key to switch between applications without stopping them. But that's already history. Linux has adapted SysRq to give the user emergency access to the kernel. But here, too, everything is not simple. The fact is that for compatibility with Windows in Linux graphical environments, a single SysRq key works like PrintScreen, and the Alt + SysRq combination recommended in the textbooks on the console, just like in Windows, stupidly puts the picture of the active window into the clipboard. Therefore, in windowed Linux, the SysRq key ... is not there either! Instead of this key, in Linux graphical environments, the magic combination Alt + Ctrl + SysRq + Latin letter / number is used, which significantly increases your power over the machine.

M - displays the amount of used memory. Works in Ubuntu if you set the output verbosity to high beforehand.

N - displays a list of real-time tasks. Also works if you set the output level high beforehand.

E - Abnormally terminates all processes except init.

I - kills all processes, including init.

T - prints a list of tasks to the console.

S - Synchronizes all file systems, writing all buffered data to the hard drive.

R - forcibly returns the keyboard to working state. In this case, the kernel starts working with the keyboard directly, bypassing the X-server, and only in ASCII codes.

T - displays a list of processes. Again, only works at a high level of verbosity.

P - dump of processor registers. The request may be of interest to those who are engaged in software debugging.

Q - Displays hard timer events. Works if output verbosity is set to high.

O - urgently shuts down the computer.

B - restarts the computer. True, it is reported that with the kernel 3.8.0-25, there is no reboot, but a shutdown. But I haven't tested it myself.

U - Remounts all file systems read-only.

V - restores the console framebuffer. Let's say you are watching a video in the virtual console (yes, Linux, unlike Windows, allows this too), and you urgently need to remember what you were doing in the console before starting the video. The command will restore the console framebuffer. In general, it would be worthwhile to tell in more detail about this amusing thing - the framebuffer, but not in this article.

W - Shows all hung tasks, if any.

Z - Outputs the contents of the kernel trace buffer.

So, SUDDENLY your Linux hangs so that even rebooting the Xs with Alt + Del + BS does not help. Calm, only calm. In no case do not rush to press the reset button on the computer case. There is a very high probability that you will not lose data when you press consecutively. keys R-E-I-S-U-B(hold Alt + Ctrl + SysRq!). And you know what? You can always instantly turn off a normally working computer by pressing Alt + Ctrl + SysRq + O. Unless, of course, you closed your programs. :)

However, it seems dangerous to make the magic SysRq available if you let other users work remotely on your machine, or if you yourself work with it remotely. The fact is that the break signal sent from the remote console can be interpreted as Alt + SysRq, with all the ensuing consequences. Therefore, if you decide to give remote access to your machine, just in case, first reset the kernel.sysrq variable in the system config. You can also write a simple script on the bash for this and even screw a button on the desktop to it so that you do not bother editing the system config control file every time. Good luck!

Let's take a look at how to restart or shutdown your computer from the command line. I use this when, when installing a driver or with a heavy load on the processor, the interface stops responding to my actions (although this happens very rarely). You can kill a "gluttonous" process through the command line, but it is not always known what process it is, so a quick solution is to restart the computer.

Restart your 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 (when entering a password, characters are not displayed). And I execute the command:

Sudo reboot

You will need to enter the administrator password again and press Enter. The computer will 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 turn off the computer from the command line, you need to run the command:

Sudo shutdown -h now

You can also turn off the computer by running the command:

Sudo halt

And also you can use.

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

Shutdown command syntax

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

Note

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

5 practical Linux shutdown command examples

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

If you just use the shutdown command, it will start 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 shutdown the system immediately, but when they see a message such as UTC timestamp they are often confused.

1. Immediate shutdown of the system.

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

Sudo shutdown now

2. Schedule a system shutdown

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

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

Sudo shutdown +20

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

Sudo shutdown 15:00

Needless to say, the key time and time zone is the system time.

Note

Five minutes before the scheduled shutdown time, the system will not allow any login activity. It means that New user cannot log on 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 the new command just to reboot the system. You can use shutdown command in Linux to reboot.

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

Sudo shutdown -r

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

So, if you used shutdown -r without any timing arguments, it will restart in one minute.

You can schedule a reboot in the same way as when shutting down.

Sudo shutdown -r +45

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

Sudo shutdown -r now

4. Sending a custom message

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

By default, all registered users will be notified of the scheduled outage and time. You can configure the broadcast message in the shutdown command itself:

Sudo shutdown 15:00 "The system will be shutdown to update hardware, please save your work."

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

5. Cancel scheduled shutdown

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

Sudo shutdown -c

And if you've passed the scheduled shutdown message like a good sysadmin, you can also notify other users to cancel the scheduled shutdown.

Sudo shutdown -c "scheduled shutdown was canceled"

Halt vs Power off

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

Historically, in the past, computers were used to shutdown the system and then printed a message like “shut down normally now” and then the computers were turned off using physical switches.

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

These were the most common and most useful examples of the shutdown command in Linux. 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.

File Buffers Linux systems are stored in memory and only occasionally written to disk. This speeds up disk I / O operations, but increases the risk of data loss in the event of a sudden failure.

Traditional UNIX and Linux systems have been very demanding in terms of shutdown procedures. Modern systems are more tolerant (especially when it comes to a highly secure filesystem like ext3fs), but it is still better to shutdown gracefully if possible. Incorrect shutdown of the computer can lead to the appearance of hard-to-find, subtle errors, and sometimes to a complete system crash.

Reboot the system to personal computer- a means of solving almost all problems. But when working in Linux, we advise you to think first and only then reboot. Problems in Linux are usually hidden and complex, so reboots give the expected result much less often than on other systems. In addition, the Linux reboot process takes a long time, which is inconvenient for users.

It is necessary to reboot when a new device is connected or a working device freezes so that it cannot be initialized. If the configuration file is modified, which is polled only at initial boot, then the changes will take effect only after a reboot. And finally, if it is impossible to register in the system, there is simply no other way out but to reboot.

If one of the system startup scripts is modified, then you need to reboot at least in order to check whether the system is functioning successfully after the changes. If any problem does not appear in the next few weeks, later you will hardly remember the details of the latest changes.

Unlike bootstrapping, which is done in a single way, you can stop and reboot the system in different ways:

  • turn off the power;
  • enter the shutdown command;
  • use the halt and reboot commands;
  • change the runlevel of the init daemon using the telinit command;
  • execute the poweroff command to ask the system to turn off the power.

Power off in Linux

Even on desktop systems, turning off the power is not the best way to shut down the system. This can lead to data loss and damage to file systems.

Some computers have a software stop button that, when pressed, executes a series of commands that gracefully shut down the system. If you are not sure if your computer supports this feature, do not try to find out by pressing the power button while the system is running! There will be much less problems if you stop the system manually.

Of course, foresight is good within reason. In the event of a flood or fire, it is better to turn off the power, if there is simply no time for a correct shutdown of the system. Once upon a time, there was an emergency button in the machine rooms, which made it possible to turn off all equipment at the same time.

Command shutdown: the correct way to shutdown the system

The shutdown command is the safest and most correct way to shutdown or reboot the system, or return to single user mode.

You can instruct the command to pause before shutting down the system. While waiting, the command sends messages to registered users at gradually decreasing intervals, warning of an impending event. By default, the messages indicate that the system is shutting down and indicate the time remaining until the shutdown. If desired, the administrator can add his own short message explaining why the system is halting and approximately how long it will have to wait before being able to log in again. After executing the shutdown command, users will not be able to log in, but they will see the message provided by the administrator.

The shutdown command can be used to specify what the system should do after executing the command: stop (-h) or reboot (-r). You can also specify whether a forced disk check should be performed after a reboot using the fsck command (-F) or not (-f). By default, Linux will automatically skip this check if the filesystems have been properly unmounted.

The following command reminds users of the scheduled service procedure and shuts down the system at 9:30 AM:

$ shutdown -h 09:30 "Going down for scheduled maintenance. Expected downtime is 1 hour"

You can also set the relative shutdown time. For example, the command below will start the shutdown process after 15 minutes:

$ shutdown -h +15 "Going down for emergency disk repair."

Command halt: an easier way to stop

Halt command performs all the basic operations required to halt the system.

It is usually invoked with shutdown -h, but it can be used by itself. The command logs the shutdown, kills nonessential processes, executes the sync system call, waits for disk writes to complete, and then terminates the kernel.

The -n option suppresses the sync system call. The halt -n command is used after restoring the root partition with the fsck command so that the kernel cannot overwrite patches with older versions of the partition stored in the cache.

Command reboot: fast restart

The reboot command is almost identical to the halt command. The only difference is that the system reboots and does not stop. The reboot mode is also invoked by the shutdown -r command. The reboot command also supports the -n flag.

Command telinit: change the runlevel of the daemon init

You can use the telinit command to instruct the init daemon to move to a specific runlevel. For example, the command