قالب وردپرس درنا توس
Home / Tips and Tricks / How to restart or shut down Linux with the command line

How to restart or shut down Linux with the command line



  Terminal on a Linux desktop

Do you feel like restarting? This tutorial will show you how to restart or shut down your Linux or MacOS computer cleanly and safely from the command line.

We go down

Sometimes you just have to go to restart or total shutdown. If you are working on a GUI-less server or if you are on a SSH session to a remote computer, the command line is your only option. Linux and Unix-like systems like MacOS provide multiple commands to shut down or restart the system directly from the command line. The commands you can use are:

  • shutdown
  • restart
  • content
  • stop
  • Looking at the men's pages for these commands can be confusing. Depending on the command line options you choose, all of these commands can perform shutdowns, restarts, and system shutdowns. In fact, pages for restart content and poweroff contain exactly the same information.

     man page for content command

    ] What is behind this?

    The answer lies in the systemd bootstrap system that replaced the honorable System V init system. In the Linux world, Fedora began using systemd 2011. Since then, it has been adopted by many distributions. Debian and Ubuntu switched to systemd in 2015. On systemd -based distributions, shutdown was started on and poweroff commands are effective shortcuts pointing to the command systemctl . Retaining these commands provides a degree of compatibility with System V init -based distributions. This means that shell scripts (and the hard-core system kernel system cores) will not cool if they are moved to a computer with a systemd distribution running on it.

    Using Shutdown

    Shutting down or restarting a multi-user system means you have to plan ahead. You have to decide when to go to the shutdown or restart and warn the other system users that the shutdown will come and when. If it is your own computer and you are the only one who uses it, life is much easier.

    To run any of these commands you must be in the group sudo . This means that you must have superuser permissions and be able to use the sudo command. If the command you issued will take effect immediately and will not affect other logged in users, you do not need to use sudo . If you try to use one of these commands and the command is rejected, try again with sudo .

    By default, the command assures shutdown that all processes are stopped clean, all file systems are synchronized and all CPU activity has ceased. This is the "lame" state. It then sends a message to the hardware to interrupt the power. This is of course a shutdown or a "poweroff" state. " width="650" height="300" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/>

    It is common to send [shut down] some parameters, e.g. a time string and a message that will be sent to the logged in users warn them of the shutdown. Let's schedule a shutdown for 15 minutes from now. Write shutdown a space, +15 a space, and then the message to send to the users.

      Closing +15 Shutting down in 15 minutes! 

      Turn Off Command +15 Message

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

    We get an answer that confirms that a shutdown is planned and when it will happen. Logged in users will receive the message we provided.

     shutdown notification

    To cancel a shutdown, use the -c c option

      Shutdown cancellation command

    Even if you do not receive a notification that your shutdown has been interrupted, you get logged in users.

     Cancellation notice [19659005] If you do not specify a time string, a shutdown will be scheduled for one minute from now on. Note that you cannot send a message to your logged in users unless you specify a time string.

      Shutdown 

      Shutdown command No parameters

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

     Close Now

    The time string can be a fixed time, for example, 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 logs are prevented.

     Closing 23:00 with message

    We know the standard action of shutdown making the computer go down to the steady state and then into the shut-off state.

    • The -H (lame) option takes your computer down to the stop mode, but will not request the hardware to shut down. [19659007] -P (poweroff) is the default action.
    • The -r (reboot) option takes your computer down to the stop mode and then restarts it. -h (stop and shutdown) is the same as -P -P . If you use -h and -H together, the option takes -H priority.
    • -c (cancel)

    Here is an example where we have planned a restart.

      Shutdown -r 08:20 System Restart at 08:20 

      Shutdown Scheduling a Restart scrn4

    Restart, Stop, and Shutdown Commands

    These commands perform the action their name suggests. But everyone will accept command-line options to get any of them to restart, stop or shut down. But why confuse things? These commands are best used at nominal value.

    If you want to restart now, use restart . If you want to turn off the power now, use poweroff and if you want to stop the system now, use content .

      restart the command in a terminal window " width="644" height="55" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/> 

      poweroff 

      [off] the power off command in a terminal window " width="644" height="55" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/> [19659000] 

    These commands have immediate effect. If any of these commands are refused, they are preceded by sudo . But be aware, a refusal is usually because there are other users who are logged into the system you are about to take offline.

    Which command is right for me?

    In several user environments, use shutdown to perform these actions will give you more control. The possibility of scheduling shutdowns and restarting, and alerting users with a broadcast message, will be invaluable in these cases. ! The function (f, b, e, v, n, t, s) [if(ffbq)avkastningn=ffbq=function(){ncallMethodncallMethodapply(nargument):?nqueuepush(argument)}if(!f_fbq)f_fbq=n;npush=n;nloaded=0;!nversion='20';nqueue=[]; t = b.createElement (e); t.async = 0 !; t.src = v; s = b.getElementsByTagName (e) [0]; s.parentNode.insertBefore (t, s)} (window, document, & # 39; script & # 39 ;, "https: //connect.facebook.net/en_US /fbevents.js');fbq(&# 39; init & # 39;, & # 39; 335401813750447 & # 39;); FBQ (& # 39; track & # 39;, & # 39; Page View & # 39;); [19659060]


    Source link