Unix Command to Shutdown

What is the most basic way to shutdown via the command line? Thanks.

Steve M.

iMac G4 17 inch, 1 GHz, 1 GB RAM, Mac OS X (10.4.3), Iomega triple interface 250 GB HD

Posted on Nov 19, 2005 9:01 AM

Reply
7 replies

Nov 19, 2005 9:29 AM in response to Bill Scott

What will happen to open Mac applications?

The question of using Terminal to shutdown arose because of a very strange situation I encountered last evening. I was in the middle of saving a document as a PDF when all of a sudden the system started acting crazy. I would get a rapid staccato of warning beeps assiciated with the curson dancing around on the desktop from icon to icon highlighting each in rapid succession. Selecting something from the menu bar resulted in the focus rapidly shifting all along the row of choices, for example with Safari, the focus would shift from Apple to Safari to File to View to History, you get the picture. I was unable to quit open apps. I was unable to pull down the Apple menu to get to shutdown or restart or logout. I succeded in opening terminal somehow and got a few lines of gibberish followed by the prompt. I tried sudo shutdown but was not aware of using -h or -r. But somehow, just opening Terminal had cause my system to settle down and stabilize and I was able to shutdown normally from the Apple menu. System is fine now. I've never seen anything quite that bizarre (at least since OS 9!).

Thanks,
Steve M.

Nov 19, 2005 10:14 AM in response to Steve M.

Steve,
From the 'halt' man page:
The halt and reboot utilities flush the file system cache to disk, send
all running processes a SIGTERM (and subsequently a SIGKILL) and, respec-
tively, halt or restart the system. The action is logged, including
entering a shutdown record into the wtmp(5) file.
When the system is halted with the halt command, the system is powered
off.


As mentioned by others it will safely shut down the OS, but will not give apps the opportunity to ask you if you want to save docs.

Reese

Nov 19, 2005 10:38 AM in response to Steve M.

- What will happen to open Mac applications?

(From the description in man reboot: Normally, the shutdown(8) utility is used when the system needs to be halted or restarted, giving users advance warning of their impending doom and cleanly terminating specific programs.)

- They are cleanly terminated, but you probably lose all non-saved data.

Strange indeed, what happened last evening!
You could have tried shortcuts too: ⌥⌘⎋ or Control Option+CommandEject (shut down) or Control CommandEject (restart).

Also, in this case the Terminal command reboot too was appropriate.

Axl

Nov 19, 2005 5:38 PM in response to Steve M.

Hi Steve,

> What will happen to open Mac applications?

I agree with Reese and Axl; you will almost certainly not get a chance to save files open in Aqua applications. The way to shutdown in the manner like doing it from the Apple menu would be to use AppleScript. That can actually be done in the command line by using the osascript command. It would look something like:

osascript -e 'tell application "Finder" to shut down'

At least I think that's the syntax. Unlike most of the commands I post, I confess that I haven't tested this one. I can't afford to shutdown just now.
--
Gary
~~~~
Miss Wormwood, could we arrange our seats in a little
circle and have a little discussion? Specifically, I'd like to
debate whether cannibalism ought to be grounds for
leniency in murders since it is less wasteful.
-- Calvin

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Unix Command to Shutdown

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.