Ubuntu one remote uses sudo -S -p '' halt
for shutdown and does not work to the end.
leaveing monitor on with message
will now halt
[22225.11163] halted
What is the difference between sudo -S -p " halt
and sudo shutdown now
?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityThe -S
and -p
switches for sudo
have no importance in this case. Here is what they do, respectively.
The
-S
switch causessudo
to read the password from STDIN. This allows, for example, a password to be piped tosudo
throughecho
orcat
.The
-p
switch allows you to override the default password prompt and use a custom one, or none at all.
The important difference is in the two commands being issued by sudo
.
The
halt
command, if invoked without the-p
switch, simply halts the OS and stops all CPUs. Once the system is cleanly halted, the user may safely hit the Power button on his computer manually.The
poweroff
,shutdown -h now
, andhalt -p
commands all do the same thing ashalt
alone, while additionally sending an ACPI command to signal the power supply unit to disconnect the main power. This prevents you from having to physically push the Power button on your computer.
shutdown -h now
does not necessarily turn the power off either. As per man shutdown
, it depends on the system. shutdown -H now
(notice the caps on H
) is the one guaranteed to be equivalent to halt
Sep 18, 2012 at 15:01
halt
is not shutdown
, they are different commands. The former does not turn the power off, unless -p
option is used
From the manual (man halt
): "-p, --poweroff : Instructs the halt command to instead behave as poweroff."
And, in your case, -p
was not used in the halt
command, hence your computer was not powered off.
Do not confuse this -p with the one from sudo
, it's a different parameter for a different command. From man sudo
:
-S
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.-p prompt
The -p (prompt) option allows you to override the default password prompt and use a custom one.In your case, prompt
is empty (no message displayed for sudo when asking password), and -S makes sudo accept root password vi stdin (so password may be supplied using pipes and redirection from other commands instead of being typed)
There is a good answer at the Unix SE site about the shutdown
vs halt
issue: What is the difference between Halt and Shutdown commands?
As for the sudo -S -p ''
part, this will remove the message about asking the password in the terminal (You still have enter your password though)
For example running sudo <some_command>
will give this output before running this command:
[sudo] password for :
But running sudo -S -p '' <some_command>
will hide that message.
In fact, the message that you put in the quotes, is replacing the previous message.
Go ahead and try the following, and see the difference:
sudo -S -p 'Hey, I am a custom message.' ls
There are no difference between halt command and shutdown in terms of the user intention. The thin difference is that in halt you have to conveniently push the power button to shutdown the system whereas in shutdown command it will automatically instruct the Advanced Configuration Power Interface (ACPI) to sent a signal to the power unit to turn off the system.