Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Simple question: what params can be used to shutdown a computer running Linux/OSX in 30 seconds? I've always run Windows, where I would go shutdown -s -t 30 but the parameters are different. I've looked it up here but it will only let you shut a computer down at a specific time (like 8:00) rather than in a specific amount of seconds.

share|improve this question

migrated from stackoverflow.com May 12 '11 at 22:56

4 Answers

up vote 4 down vote accepted

In OS X you can shutdown in one minute using the following command:

sudo shutdown -h +1

AFAIK, it's not possible to specify seconds instead of minutes with this command.

You can also reboot by using -r instead of -h.


EDIT:

As you mentioned in your comment, you can add a delay programmatically, then shut down the system immediately with

shutdown -h now

But note that that command will require root access.

share|improve this answer
meh. So no using decimals. I suppose that's alright, I was wondering because I'm trying to work on a cross-platform Java application that can shutdown a computer. So I could just make it sleep for 30 seconds before shutting down immediately. But would sudo shutdown -h shutdown the computer without an intentional delay? – icnhzabot May 12 '11 at 22:55
@icnhzabot sudo shutdown -h now would shut the computer down immediately with no warning. – Austin May 12 '11 at 23:07
ok thanks. so for root access I should do sudo shutdown -h now right? – icnhzabot May 12 '11 at 23:29
@icnhzabot That won't work for an automated script/program because it prompts the user for their administrator password at the command line. You'd have to run your script as root and just call shutdown -h now. If you need help with that, you should make a new question (assuming you can't find the answer elsewhere). Also, don't forget to mark the best answer here as "accepted" if it answered your question. – Austin May 12 '11 at 23:43

As pointed out, the command

sudo shutdown -h +1

Adds one minute.

If you wanted to do it in seconds or hours or something very specific you could do something like:

shutdown -h `date --date "now + 60 seconds"`
share|improve this answer

Using the basic calls, I don't see a way to do it with seconds, but it looks like you can do it with minutes:

time Time is the time at which shutdown will bring the system down and
     may be the word now (indicating an immediate shutdown) or specify
     a future time in one of two formats: +number, or yymmddhhmm,
     where the year, month, and day may be defaulted to the current
     system values.  The first form brings the system down in number
     minutes and the second at the absolute time specified.

In other words:

shutdown -h +1

If you want to shut it down in 1 minute.

share|improve this answer
do you know if it would work with .5? – icnhzabot May 12 '11 at 22:53
There's an error here -- the -r option is for reboot, not shutdown. You have to use -h for shutdown. – Austin May 12 '11 at 22:54
@Austin ugh, fixed that inline. – onteria_ May 12 '11 at 22:56

Have you tried: shutdown -t 30

share|improve this answer
I can't--I don't run Linux and I'm not in possession of a computer with it installed. What's the use of the -h parameter? – icnhzabot May 12 '11 at 22:52
I edited it. I wrote the incorrect command. – XcodeDev May 12 '11 at 22:52
-h means halt, so it shuts down all system processes and daemons. – Simon Sheehan May 12 '11 at 23:47

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.