Terminal or shell command to shutdown or reboot Ubuntu Linux

by Vivek Gite · 10 comments

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

{ 10 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

Leave a Comment

Previous post:

Next post: