1

With the cmd shutdown -h +<time>you can only specify minutes for time.

I tried using decimals but it just shuts down immediately.

Background

If you shutdown from terminal then the terminal stays open when you power on and can take a while to be usable.

I hardly touch the GUI no way I'm going to scroll all the way over to the button.

I got around this by putting this in my ~/bash_profile:

alias sd='sudo shutdown -h +1 && exit' 

This shuts down after a minute, giving the terminal time to exit. Or I should say writing the cmd in this way means it gives an exit code.

Only problem is I want it to shutdown in 10 or less seconds but there seems to be no way to specify seconds.

Update:

shutdown -h now && exit
shutdown -h now; exit
shutdown -h now; anycmd

shutdown -h now; anycmd

Will never reach the next cmd as it occurs in the foreground, once it completes the computer is off.

shutdown -h +1 && exit

Confused me, it was nothing to do with the time delay, it was because the cmd occurs in the background so the exit is reached.

So you have to run the cmd in the background so that the exit can be reached.

I got the answer first after realising this:

alias sd='shutdown -h now & exit
0

3 Answers 3

4
alias sd='sleep 10; nohup shutdown -h now & exit'
1
0

It looks like you can't specify seconds.

From the shutdown man page:

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.

However you mentioned that you would like the shutdown to happen in "10 or less seconds" from executing the command...

shutdown now

Seems to be a legitimate command and will shutdown your computer in less that 10 seconds, as you request.

0
-1

I got it with this:

alias sd='sudo shutdown -h now & exit'

This stops the cmd from holding up the terminal as it goes to background so the exit is reached and the terminal closes.

Update

This cmd is unreliable, although the terminal closes, sometimes on power on the terminal will be open so now I do:

alias caff='caffeinate -dimsu'
alias sd='caff & sudo shutdown -h +1; exit'

Then close the lid.

caffeinate & is necessary as when the lid is closed the computer locks so will never shutdown.

1
  • unjustified downvote. Highest voted answer has the same cmd which was written later has an unneeded no hip and is buggy. Clearly a personal issue with this obnoxious user. Problem is unsolvable, so this is the next best solution.
    – Nickotine
    Jun 28, 2023 at 18:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .