Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to do that using the command-line, because sometimes my computer freezes and I need to force a shutdown (I know it's not good to the hardware). And: What is the difference between Halt and Shutdown commands?

share|improve this question
add comment

4 Answers

up vote 5 down vote accepted

Using the commands shutdown and reboot respectively. To log off from a terminal you can press Ctrl-D or type exit.

share|improve this answer
1  
or type exit instead of Ctrl+D ... or just execute shutdown/reboot via SSH ssh root@brokenbox reboot –  Bananguin Jul 5 '12 at 21:58
add comment

If it is a frozen X session, hit ctrl+alt+f1 to get to a console. Log in and from there, execute /sbin/shutdown, /sbin/reboot or /sbin/shutdown -r now. Depending on permissions, you may need to prefix these commands with sudo or first su to become root.

You may also be able to kill the offending process. Run ps aux to list all processes and look for ones which are using a lot of CPU and/or memory (third and fourth columns). Use kill <pid>, where pid is the number in the second column of the ps output). If this doesn't kill the process, you may need to run kill -9 <pid> to forcefully kill it.

share|improve this answer
    
ctrl+alt+f1 may not work on all systems (some have the X session there), but ctrl+alt+f3 will on most, except for installation live systems maybe. –  Jonas Wielicki Jul 12 '12 at 17:30
add comment

If your BIOS is setup in a way where you have to press the power-button more than X seconds to actually turn off the machine, press the power-button once. This will give the acpi-signal for shutdown/halt/poweroff.

share|improve this answer
add comment

If you can still access a text mode console, or if you can log in remotely:

  • You can use ps or other process listing tools and kill to try killing some processes. A few programs will save your work (at least to a recovery file) if they receive a kill -HUP or plain kill. They might not have time to do it if you go straight for rebooting.
  • Run sudo kill followed by a process ID to kill a process that's running as root or some other user who is not you.
  • Run reboot to reboot (e.g. sudo reboot if you use sudo to gain administrative access). Run halt to power the computer off. Both of these call shutdown with appropriate options.

If absolutely everything is hosed, but you have console access, you can use magic SysRq to at least flush all file changes to disk unmount filesystems cleanly. Press

  1. Alt+SysRq+E to send SIGTERM to all processes (optional).
  2. Alt+SysRq+S to synchronize (flush) filesystem changes to disk.
  3. Alt+SysRq+U to forcefully unmount (actually, remount read-only) all filesystems.
  4. Alt+SysRq+B to reboot.

(Note: you'll sometimes see “REISUB”, but the R and I steps are useless.)

share|improve this answer
1  
Just to make it easy to remeber, its BUSIER backwards. –  Spidey Jul 11 '12 at 21:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.