Terminal or shell command to shutdown or reboot Ubuntu Linux

by admin on March 9, 2007 · 30 comments

in Howto, Linux, Tips, Ubuntu Linux

So how do you shutdown or reboot Ubuntu Linux from a terminal or a shell prompt? If GUI is working you can always click on a Quit button. If GUI is not working or if you are working remotely over ssh type the following command:

To shutdown / poweroff Ubuntu Linux

Type the command:
sudo halt
OR
sudo shutdown -h now

To reboot Ubuntu Linux

Type the command:
sudo reboot

More information can be found about these two commands by typing following commands (man page):
man reboot
man shutdown

{ 30 comments… read them below or add one }

1 David Taté February 22, 2008 at 8:14 pm

thank you

Reply

2 Rizme September 3, 2008 at 3:05 am

thank you. very usefull shell commands

Reply

3 rishie December 14, 2008 at 8:34 pm

What would be the shell command to get the shutdown/restart popup? The reason why I am asking is because I want to change the command on one of the applets on AWM from logout to shutdown/restart. I would rarely if ever use the logout feature since I am the sole user of my computer.

Reply

4 HImadri Nayak August 10, 2009 at 3:10 am

I have a dual booting machine having XP SP2 and UBUNTU 8.04. I have installed UBUNTU under XP. Now using secured Shell from an remote PC I want to logout from ubuntu such that it would not go to the dual boot screen where Windos XP is the firs option and I have no control over it from remote PC to stop the machine to to go to Windows. This is only possible if I use logout not restart or reboot. So, please tell me how is it possible from terminal?

Reply

5 Brian October 29, 2009 at 6:10 am

Was just browsing and saw this. I have a dual boot as well. and wanted to control the same problem when booting.

what I did was write a script that edits the grub configuration file. the file is in /boot/grub. I have 9.10 and the file is called grub.cfg, but in older versions it is called menu.lst.

you are looking for a line that says “default x” where x is the default row that grub starts on. starting from 0(in 9.10 this is “default = x”). soooooo…

i run my script and it goes and finds that line and changes it so that instead of being “default = 0″ which will turn my computer on with ubuntu as the default system, it now says “default = 6″ because windows is the 7th item on my grub menu. at the end of my script i put ‘shutdown -r now’ which reboots the computer.

note, this script has to be run with root permission to edit the file(and in ubuntu 9.10 the permissions have to be adjusted on the file to allow root to write to it).

What I did was attach this script to an launcher on my taskbar so whenever I click it it runs “gksu scriptname” note also that gksu must be used with the launcher because no terminal will appear for you to enter the root password if you just use “sude” here.

here it is written in perl, this should work on 8.04 without any changes assuming things are configured normally. just change the numbers “0″ and “6″ accordingly for your system.

here:

Reply

6 João Rodrigues January 27, 2010 at 3:17 pm

There is already a command that does basically the same thing: grub-reboot.

You can do
grub-reboot 0
to instruct the system to reboot, and set grub menu entry 0 (the first) as the system to boot next. Substitute 0 for 1, 2, etc to reboot some other entry. The command must be run by root and will ask for confirmation, but you can pipe an answer into it.

João

Reply

7 mech October 17, 2009 at 4:44 pm

Thank for the commands.

Reply

8 poswer November 5, 2009 at 7:51 am

i am using ubuntu 8.04 LTS amd 64 os some i try to shutdown my box halt -p shutdown or poweroff not able to shutdown still system is running so after i shutdown manually can you give sol what is problem.

thanks

Reply

9 Demba Sonko November 6, 2009 at 10:03 pm

Thanks for all efforts

Reply

10 Joseph Thornton January 9, 2010 at 7:17 pm

Thanks for sharing these commands with us.

Reply

11 Gana March 13, 2010 at 6:22 am

thank you

Reply

12 Mahesh March 13, 2010 at 3:01 pm

very very thank you……..

Reply

13 Atif April 17, 2010 at 8:04 am

I’m using ubuntu 8.04 LTS with squid proxy server its working fine after restarting through terminal window
Thank you for useful commands

Reply

14 arif May 2, 2010 at 1:12 am

hi,

i need to have LAMP with php 5.2.9 to match my wamp developed php scripts on windows xp.

will any one be knd enough to show me exactly how i can install/compile/upgrade to php 5.2.9 on my ubuntu server.

thanks.

Reply

15 Ian January 3, 2011 at 11:05 pm

Google “xampp”
It is a lampp stack for both Linux and Windows, so you would have the same versions in both.
Current version of PHP is 5.3.1, but older versions are available

Reply

16 Khizar June 14, 2010 at 1:09 am

Hi,

Is there any way of changing windows settings through ubuntu. The last thing I did before XP would keep restarting, is that I went into msconfig and checked the /safeboot box.

Thanks!

Also, what is the root username for ubuntu?

Reply

17 Ian January 3, 2011 at 11:07 pm

At the risk of starting a flame war, there is no “root” account (as such) for Ubuntu.
Run “sudo -s” and input your own password to get a root shell

Reply

18 Joost April 1, 2011 at 12:40 pm

There is a root but it is by default disabled, it is very simple to enable it:
sudo -i
will give you a rootshell,
you want to login as root, then use the “passwd” command in this shell it will ask for a new root password without asking the old root password,
now you can log in as root in any shell (eg:CTRL+ALT+F1-6) but not in graphic shell.

Reply

19 chetan December 11, 2010 at 5:44 pm

hi,,how to cancel an existing shutdown operation and create a new one???

Reply

20 dizar December 24, 2010 at 2:24 am

chetan December 11, 2010 at 5:44 pm

hi,,how to cancel an existing shutdown operation and create a new one???

sudo shutdown -c

Reply

21 indra pd December 24, 2010 at 3:07 am

thanks boss

Reply

22 ehsan February 16, 2011 at 1:21 pm

Thanks, very usefull

Reply

23 gonkyouka March 17, 2011 at 7:10 pm

Thank you so much for this website. I am looking for a shutdown command but I end up reading your article about coral. :D

Reply

24 Joost April 1, 2011 at 12:44 pm

there is more: I prefer runlevel switching:

sudo init 6
= reboot
sudo init 0
= halt
sudo init 1
= boot into single user mode

Reply

25 Andre January 28, 2012 at 8:49 am

you can also use

shutdown -ry 10

10 is 10 minutes, you can change it if you need to shutdown programs first.
you can also put this in a sh script.

Reply

26 van April 3, 2012 at 2:49 pm

i want someone to help me ………..how to shutdown another linux computer through my own wire……………..without the other person notice

Reply

27 Sheldon May 11, 2012 at 7:02 am

Thanks pal..

Reply

28 nikhl August 4, 2012 at 12:02 pm

how to remote restart computer using ubuntu terminal ???

Reply

29 Vibhav Sinha November 14, 2012 at 5:09 pm

Thanks! Is there any way to set ubuntu to start after few hours(given time). That is I want my server to be shutdown for three hours. How to set this?

Reply

30 Lucho January 16, 2014 at 10:39 pm

Thanks a lot! I really need that basic commands.

Reply

Leave a Comment


+ 6 = eight

Previous post:

Next post: