Ninja Tricks

November 11, 2006

Shutdown

Filed under: OS, S — thelaziestninja @ 9:13 am

Terminals are my favorite means of communication with a computer. Consequently, I really hate being forced to find a start menu/gnome menu/k menu/apple menu/other nonsense when performing simpke tasks. In particular, I found that it would be extremely useful if I can shutdown a computer from a command line, rather than through said annoying menu. Hey, maybe I’m just not a mouse kind’a guy.
Posix
The command for Posix systems is pretty simple. The command “shutdown” takes at least two parameters, one being the time that you wish to shutdown the computer. Generally, this is set to “now,” but should you want to warn users logged in to the system, or at least give them some time to save their work, giving another time frame may be best. The first parameter, a flag, must indicate what sort of shutdown you wish to perform. For example, -h halts the computer, i.e. turns it off, while -r restarts said computer. The shutdown program requires super user privileges, however, so, unless you change permissions, you will need to use sudo in Ubuntu, Debian, etc. or su root in non-sudo environments.

sudo shutdown -h now

Shuts the computer down immediately.

Windows

Though one might not expect the average Windows user to have a command.exe window running at all times, I know I do. Windows asks for similar parameters, requiring a /s flag for shutdown or a /r flag for restart. By default, Windows gives users about thirty seconds, during which a message will be displayed on their screen, and, should there be a problem, you can abort (/a flag). If you’d rather not wait, you can give a time parameter that will tell Windows to shutdown in a different time period. Unlike Posix, users do not need special privileges (though I haven’t tested this from a “guest” account).

shutdown /s /t 0

Shuts the computer down, beginning in zero seconds

Blog at WordPress.com.