Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Challenge:

In the programming language of your choice, shutdown the machine that your code was executed on.

Rules

  • No shutting down by resource exhaustion (e.g.: forkbomb to force shutdown)
  • You are allowed to write code that only works in a specific environment/OS, if you wish.
  • Standard loopholes are forbidden

This is , thus the lowest amount of bytes wins!

share|improve this question
51  
I got friends, who do this in school and think they are 'hacking' :D – RaisingAgent Jan 24 at 14:00
11  
We should come up with some rule once to stop such `whatever`; Bash/Perl/PHP/Ruby/etc. stupiglots. – manatwork Jan 24 at 14:22
218  
Windows, 0 bytes. Leave the computer on for a few days and let automatic updates do their work – Luis Mendo Jan 24 at 15:17
19  
Anybody else notice the lack of TIO-links? – steenbergh Jan 24 at 16:37
8  
@MontyHarder After reading that page I have decided to coin the term shatdown: past tense of the verb shutdown – FGreg Jan 24 at 17:34

52 Answers 52

Assembly (x86/x64, Linux, as), 22 21 19 bytes

mov  $0x58,       %al  # 2 bytes: b0 58
mov  $0xfee1dead, %ebx # 5 bytes: bb ad de e1 fe
mov  $0x28121969, %ecx # 5 bytes: b9 69 19 12 28
mov  $0x4321fedc, %edx # 5 bytes: ba dc fe 21 43
int  $0x80             # 2 bytes: cd 80

Must be run as root.

This is equivalent to pressing the power button and not a safe way to power off your PC. Make sure you close all open applications and execute sync to flush all file system buffers before executing this program, to at least minimize the risk of file corruption.

Test run

$ as -o poweroff.o poweroff.s
$ ld -o poweroff   poweroff.o
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078
$ sudo sh -c 'sync && ./poweroff'
root's password:

Followed by darkness.

How it works

int $0x80 invokes a software interrupt. It works on both x86 and x64, but has been deprecated for over a decade now and should not be used in production code. x64 code should use a syscall (syscall instead. x86 should use sysenter, but is is too cumbersome for code golf.

The resulting action from the syscall depends on registers EAX - EDX, ESI, and EDI. The Linux Syscall Reference shows all syscalls that are available via int $0x80.

When EAX holds 0x58 (88), reboot is called, which can also be used to power off, put to sleep, or hibernate the computer, as well as switching kernels and disabling or enabling the Ctrl - Alt - Del key combo.

At the start of the program – and by compiling with as or gcc -nostdlib, we can make sure that we're actually at the start of the program – most registers are set to 0. This includes EAX, so we can use mov $0x58, %al to set the lower 8 bits of EAX to 0x58, thus setting EAX itself to 0x58. This saves two bytes over manually zeroing the register with xor %eax, %eax and one more over the straighforward mov $0x58, %eax which encodes 0x58 in 32 bits.

The first two arguments to reboot are magic numbers, presumably to prevent accidental reboots, and are read from registers EBX and ECX. Unless these numbers are equal to certain constants, reboot refuses to perform any action.

  • The first magic number must equal 0xfee1dead (feel dead), probably referring to the power off / death of the PC.

  • The second magic number can be equal to four different constants, although the latter three did not work in ancient versions of Linux. All of them seem to refer to the subsequent power on / birth of the PC. Patricia, Daniela, and Celeste Torvalds are Linus Torvalds's three daughters.

    • 0x28121969 represents Linus Torvalds's birthday (December 28, 1969).

    • 0x05121996 represents Patricia Torvalds's birthday (December 5, 1996).

    • 0x16041998 represents Daniela Torvalds's birthday (April 16, 1998).

    • 0x20112000 represents Celeste Torvalds's birthday (November 20, 2000).

  • The EDX register selects the type of "reboot" we want. 0x4321fedc is RB_POWER_OFF, shutting the PC down and powering it off.

  • Finally, the value of the ESI register is ignored for RB_POWER_OFF; the value of the EDI register is ignored entirely by reboot.

Alternate version, x64-only, 19 bytes

On x64, we can use a proper syscall for the same byte count.

mov     $0xa9,       %al  # 2 bytes: b0 a9
mov     $0xfee1dead, %edi # 5 bytes: bf ad de e1 fe
mov     $0x28121969, %esi # 5 bytes: be 69 19 12 28
mov     $0x4321fedc, %edx # 5 bytes: ba dc fe 21 43
syscall                   # 2 bytes: 0f 05

The only differences lie in the instruction (syscall vs int $0x80), the value of __NR_REBOOT (0xa9 vs 0x58), and the involved registers.

share|improve this answer
    
Do we normally count assembly as compiled bytes without the framing bytes required for exe header? – Joshua yesterday
    
Yes, because each instruction corresponds to specific bytes in the binary file. ELF files (or whatever format your OS uses) are considered a different language and would have to be created manually to achieve a decent score. – Dennis yesterday
1  
Excellent answer. Just one little detail - "0xfeeldead" is not a hexadecimal constant, strictly speaking... – Nayuki 18 hours ago
    
@Nayuki Uh, how did that L get in there? Fixed. – Dennis 15 hours ago

PowerShell, 13 bytes

Stop-Computer

Pretty self-explanatory? Doesn't work on PowerShell core, so it won't work on PowerShell for Linux/MacOS (already tried it on TIO :-D ).

Bonus Garbage Submission, 12 bytes

gcm s*r|iex

In my testing, this works on Windows 2003 with PowerShell 2.0. It won't work on most of the newer versions, and it may not work depending on which modules are installed. It's quite terrible!

This searches the list of commands for any with the pattern s*r and then runs all of them! To be clear, this is dangerous, don't do this!

The trick of course, is getting a list of commands that don't have any mandatory parameters, otherwise PowerShell will prompt for a value.

On my 2003 machine, the 3 commands it returns are:

CommandType     Name                                                Definition                                         
-----------     ----                                                ----------                                         
Application     scrnsave.scr                                        C:\WINDOWS\system32\scrnsave.scr                   
Application     ssmarque.scr                                        C:\WINDOWS\system32\ssmarque.scr                   
Cmdlet          Stop-Computer                                       Stop-Computer [[-ComputerName] <String[]>] [[-Cr...

Yes, it does launch the marquee screensaver, but no, it does not wait for it to complete before launching Stop-Computer.

This approach can work on newer machines, again depending on which modules are installed, but the best I could do on Windows 2012 and 2016 was 14 bytes:

gcm sto*er|iex

(and yeah, sure, the winbatch submission will work in PowerShell and it's shorter, but.. that's no fun)

share|improve this answer
2  
Shorter one for Win7 & Win10 (and maybe more): gcm *p-c*|iex -- and there's only the one result too! – Bob Jan 25 at 4:33
    
@Bob highly dependent on installed modules still; on my Win10 machine it returns 6 results, several of which will have mandatory parameters (so they'll prompt and never make it to Stop-Computer, which is the last result). – briantist Jan 25 at 14:52

Batch, 10 bytes

On windows, this would suffice

shutdown/s

This will set up a shutdown in one minute.

Alternatively, as @flashbang points out:

shutdown/p

This shuts down the computer immediately.

share|improve this answer
66  
Press the big button on the front of your computer = 0 bytes – RaisingAgent Jan 24 at 13:53
86  
@RaisingAgent Here at PPCG we solve our problems in code. Physical labour is frowned upon. – steenbergh Jan 24 at 13:54
11  
@steenbergh I don't know... pressing one big button vs 10 keystrokes? I'll go with the button – WorldSEnder Jan 24 at 21:01
10  
@RaisingAgent Your proposal has scalability issues. Try doing it for 10.000 computers four times a week. – Emilio M Bumachar Jan 26 at 12:14
7  
@RaisingAgent real men use the switch that's right on the PSU – Cruncher Jan 26 at 14:18

GRUB shell, 4 bytes

Golfed

halt

Command: halt --no-apm

The command halts the computer. If the --no-apm option is specified, no APM BIOS call is performed. Otherwise, the computer is shut down using APM.

Bonus

Here is a proof that GRUB shell is indeed Turning-complete (see comments):

enter image description here

share|improve this answer
    
grub shell is not a "programming language" - it's not Turing complete – Alnitak Jan 25 at 11:38
    
@Alnitak really? Even though you can load lua as a module? But note this code also works in bash. – abligh Jan 25 at 12:14
7  
@Alnitak, what makes you think so ? It features a rather advanced built-in scripting language, which has a syntax quite similar to that of GNU Bash and other Bourne shell derivatives and supports variables, conditional constructs, functions and more, so obviously, it is Turning-complete, by any measure. – zeppelin Jan 25 at 12:17
1  
OK, I'll take that back - I didn't find that stuff when I looked – Alnitak Jan 25 at 12:32
14  
When it cannot display a spinner it is obviously not Turning-complete – J_F_B_M Jan 26 at 11:31

65C02 machine code, 1 byte

STP instruction (0xDB):

STP stops the clock input of the 65C02, effectively shutting down the 65C02 until a hardware reset occurs (i.e. the RES pin goes low). This puts the 65C02 into a low power state. This is useful for applications (circuits) that require low power consumption, but STP is rarely seen otherwise.

(Source: http://www.6502.org/tutorials/65c02opcodes.html)

xxd dump:

00000000: db                                       .
share|improve this answer
    
Noice. I was an Apple II hacker back in the day and didn't even remember this opcode. – kindall Jan 25 at 19:06
1  
Yeah, after writing a 65c816 emulator with more features and saw this challenge I knew what to do :P Also, looks like this is the only 1 byte answer so far! \o/ – therealfarfetchd Jan 25 at 19:17

Matlab, 21 Bytes

system('shutdown -s')

I haven't tried this (closing all programs to do a restart in the middle of the day isn't really tempting), but it should work.. This works...

I'll add a short explanation later, my laptop is currently off.

share|improve this answer
87  
"I'll add a short explanation later, my laptop is currently off." <- The danger of a shutdown challenge – Suever Jan 24 at 14:08
4  
Axaxaxaxa, well, restarting your computer every once in a while can't be bad :) – RaisingAgent Jan 24 at 14:14
5  
Does ruin your uptime, though – Wayne Werner Jan 26 at 19:02
    
Why submit this as MATLAB, instead of submitting shutdown -s as shell? – immibis Jan 27 at 5:50
5  
Because for me, shell is either something I find on the beach, or a gas station. – Stewie Griffin Jan 27 at 7:18

x86 assembly, Lenovo Z510, DOS COM or Bootloader, 7 bytes

BITS 16

mov ax, (1 << 13) | (7 << 10)
mov dx, 1804h
out dx, ax

Assembled into B8 00 3C BA 04 18 EF

I'm exploiting "You are allowed to write code that only works in a specific environment/OS, if you wish" to the ultimate level: this will only work on Lenovo Z5101.

This writes SLP_TYPa << 10 | SLP_EN to the PM1a_CNT ACPI register, I dumped this values from the ACPI tables months ago for an answer about shutdown (where I give a bit of context to the code above).

This can be run either under DOS as a COM (just write the binary data into a file and change extension to "com") or as a bootloader.
For the latter write the standard signature and beware of the issues with modern firmware.


1 Not strictly true, any system that happens to have the same ACPI configuration will also shutdown.

share|improve this answer
10  
Upvoted because of the limited platform. – pipe Jan 26 at 14:39

MATLAB, 11 bytes

!shutdown/p

Somewhat similar to Stewie Griffin's approach. However, MATLAB has way shorter ways of invoking system commands; in this case, ! is used. Windows does not need .exe for command names, so that's left out as well. The / option is still supported (I'm running Windows 10), and negates the need for the space. Alternatives are:

system shutdown/p % 17 bytes; uses so-called 'command' syntax.
dos shutdown/p    % 14 bytes; the 'dos' command can be used just as well.
share|improve this answer

SmileBASIC (3.3.2), 14 bytes

READ VAR(A)[0]

Triggers a crash causing the 3DS to restart. I hope this counts.

share|improve this answer
    
I thought this had been patched... Please include a version number. – wizzwizz4 Jan 24 at 19:05
2  
It has been patched in version 3.5, which hasn't been released outside of Japan yet. – 12Me21 Jan 24 at 19:35
4  
@12Me21 Sure it counts. Nice choice of environment. – P. Ktinos Jan 24 at 21:46

Bash, 7 6 bytes

init 0

Assuming that the program is run as root.

share|improve this answer
    
Indeed, powering off the machine is required. Thus you need 'halt -p' as a valid answer – P. Ktinos Jan 24 at 14:07
4  
This editing massacre :) – RaisingAgent Jan 24 at 14:08
    
@P.Ktinos: poweroff is a single word, although slightly more letters. – ccpizza 2 days ago
1  
@ccpizza Right, but the typical scoring criteria is byte count – Suever 2 days ago

Java, 101 98 62 42 bytes

()->{Runtime.getRuntime().exec("init 0");}

As @Snowman pointed out, the question didn't specify if a full program was needed, so this should still be acceptable.

share|improve this answer
2  
It's shorter to replace class with interface as that allows you to omit public from main. – Pavel Jan 24 at 15:42
6  
You can use a method, since the question did not specify the submission must be a full program: void f()throws Exception{Runtime.getRuntime().exec("shutdown/s");} – Snowman Jan 24 at 18:12
1  
Wouldn't the Linux version be a bit shorter? – jpmc26 Jan 25 at 1:32
1  
()->{Runtime.getRuntime().exec("init 0");} or tentatively ()->Runtime.getRuntime().exec("init 0") (can't check at the moment). It's a lambda implementing a custom void, no-args-throwing interface. – Olivier Grégoire Jan 26 at 12:23

Commodore 64, 11 bytes

0 sys64738

This is from the BASIC prompt. Or...

Commodore 64, 6502 assembly, 3 bytes (assembled), 16 bytes (source)

*=8000
JMP $FCE2
share|improve this answer
    
I think that using the Commodore 64's direct input mode from BASIC with sys64738 will use zero bytes as there is no program or anything else to store; You are using screen RAM but that RAM will already be filled with spaces, so you're just replacing those spaces with text. – Shaun Bebbers Jan 24 at 17:03
2  
The source code takes up space. Just because it doesn't reserve space on the target machine doesn't mean it takes up 0 bytes. Otherwise the answer would be ``. – wizzwizz4 Jan 24 at 18:24
3  
You don't need the space between the 0 and the sys64738, you can replace the sys with the shortcut form sY, and I don't count the trailing newline in program length. However, I don't think your code meets the requirements: the code at 64738 does a soft reset, not a poweroff. – Mark Jan 24 at 22:46
2  
Does not power off. – TecBrat 2 days ago
1  
I once spilled beer on my Commodore 64, that powered it off permanently. Does this count? – Shaun Bebbers 2 days ago

Python 2, 29 bytes

import os;os.system('init 0')

Works on Linux systems and needs root privileges.

For Windows, 33 bytes

import os;os.system('shutdown/p')

This just might be the least interesting or helpful code I have ever written.

share|improve this answer
1  
Someone else posted the Linux shell version. – jpmc26 Jan 25 at 1:34
1  
Ah ok, my bad.. – FlipTack Jan 26 at 19:59

C++, 51 40 bytes

-11 bytes thanks to Ingve!

#include<os>
int main(){OS::shutdown();}

Only works in IncludeOS (v0.10.0-rc.1)

Test:

$ pwd
/home/simon/IncludeOS/examples/demo_service

$ cat service.cpp
#include<os>
int main(){OS::shutdown();}

$ mkdir build && cd build && cmake .. && make && cd ..
[...]

$ boot build/IncludeOS_example
[...]
================================================================================
================================================================================
 IncludeOS v0.10.0-rc.1-9-g151a2b9
 +--> Running [ IncludeOS minimal example ]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

$
share|improve this answer
    
Now i am curious about IncludeOS – Karl Napf Jan 25 at 19:57
    
@KarlNapf Alfred held a great presentation at CppCon 2016 about IncludeOS: youtube.com/watch?v=t4etEwG2_LY if you want to know more :-) – gurka Jan 25 at 20:05
1  
You don't need to use void Service::start, int main works in IncludeOS as well. – Ingve Jan 27 at 10:56

TI-Nspire CX CAS, 3 bytes

" "+" "

summing two empty strings.

On an older version of the calculator, this would crash the device and cause it to reboot (there's no way to shutdown a device without reboot apart from physical button combinations).

Video by Adriweb

share|improve this answer
    
Isn't that 7 bytes? – Roman Gräf Jan 26 at 14:52
    
meta.codegolf.stackexchange.com/a/4764/62824 @RomanGräf – devRicher Jan 26 at 14:55
    
Sounds convincing to me. – Roman Gräf Jan 26 at 14:58

AutoHotkey, 11 10 Bytes

Saved a byte thanks to Gurupad Mamadapur

Shutdown,9

AHK Supports a Shutdown command by default. The 9 is a flag, consisting of Shutdown=1 + PowerDown=8.

share|improve this answer
1  
AHK is mysterious. – Gurupad Mamadapur Jan 25 at 14:35
    
Do you need the space after the comma? – therealfarfetchd Jan 26 at 15:34
    
space after , is not needed. Try testing it with a different flag. I thought this will not immediately shut down the computer, and put it in my main script which loads at startup :D Now I've to load in safe mode and solve the problem. Sigh. – Gurupad Mamadapur Jan 26 at 15:52

C#, 79 54 53 bytes

This works on Windows.

79 bytes:

class _{static void Main(){System.Diagnostics.Process.Start("shutdown","/s");}}

54 bytes, thanks to TheLethalCoder:

_=>System.Diagnostics.Process.Start("shutdown","/s");
share|improve this answer
2  
Note the challenge doesn't require a full program and doesn't disallow taking an input (unused of course) so you could compile to an Action<int> and do _=>System.Diagnostics.Process.Start("shutdown", "/s"); for 54 bytes. – TheLethalCoder Jan 25 at 14:18
    
@TheLethalCoder, updated, thanks! – Dariusz Woźniak Jan 25 at 15:57
    
You can also remove the unnecessary space. – nothrow 2 days ago
    
Of course yes! Thank you, @nothrow :) – Dariusz Woźniak 2 days ago

AppleScript, 30 bytes

tell app "Finder" to shut down

Does exactly what it says: tells Finder to shut the computer off.

share|improve this answer

Machine code (x86, boot loader) 18 bytes

b8 01 53 33 db cd 15 b8 07 53 bb 01 00 b9 03 00 cd 15

Disassembly:

mov ax, 0x5301 ; connect to real-mode APM services
xor bx, bx     ; device id 0 - APM BIOS
int 0x15       ; call APM
mov ax, 0x5307 ; set power state
mov bx, 0x0001 ; on all devices
mov cx, 0x0003 ; to Off
int 0x15       ; call APM

You can test it in Bochs' debugger with the following commands (after starting simulation, having some disk drive set up):

pb 0x7c00
c
setpmem 0x7c00 4 0x335301b8
setpmem 0x7c04 4 0xb815cddb
setpmem 0x7c08 4 0x01bb5307
setpmem 0x7c0c 4 0x0003b900
setpmem 0x7c10 2 0x15cd
c

This same machine code will also work as a DOS executable (*.COM).

share|improve this answer

AutoIt, 11 bytes

Shutdown(1)

Shutdown function gets combination of following codes

0 = Logoff
1 = Shutdown
2 = Reboot
4 = Force
8 = Power down
16= Force if hung
32= Standby
64= Hibernate

To shutdown and power down, for example, the code would be 9 (shutdown + power down = 1 + 8 = 9).

share|improve this answer
1  
0 (logoff) is a special case here; it does not combine with Standby or Hibernate implicitly. – wizzwizz4 Jan 24 at 19:02
    
OK 0 + 32 = 32 – rahnema1 Jan 24 at 19:25
    
Hm, so does it always log off before going to standby/hibernation? – Ruslan yesterday
    
@Ruslan I do not know exactly how it works, You can refer to AutoIt user forum to receive more feedbacks:-) – rahnema1 yesterday

Clojure, 40 39 bytes

(.exec(Runtime/getRuntime)"shutdown/s")

-1 byte by changing the flag from -s to /s, which allowed me to get rid of the space.

Basically the Java answer.

Testing this was fun. Windows decided to do a firmware update on my Surface the second it shut down. Of course.

(defn shutdown []
  (.exec (Runtime/getRuntime) "shutdown -s"))
share|improve this answer

Groovy, 23 bytes

'shutdown /p'.execute()
share|improve this answer
2  
Is the space before the slash necessary? – steenbergh Jan 24 at 14:12
3  
@steenbergh Yes, it is needed. – Gurupad Mamadapur Jan 24 at 14:32
    
@GurupadMamadapur are you sure? – TrojanByAccident Jan 24 at 19:48
    
@TrojanByAccident Yes, I tested it. – Gurupad Mamadapur Jan 24 at 19:55

Windows - NativeAPI, 212 bytes

Ok this is not really the shortest version. But maybe interesting to some. This will not execute on the Win32 subsystem. However it will run when executed within the context of the native api (like autochk.exe does)

Code

#define WIN32_NO_STATUS
#include <windef.h>
#include <winnt.h>
#include <ntndk.h>
NTSTATUS main() {
RtlAdjustPrivilege(SE_SHUTDOWN_PRIVILEGE,TRUE,FALSE,NULL);
return ZwShutdownSystem(ShutdownPowerOff);
}

Build

To build this either use the WinDDK build.exe tool (with an appropriate source file for NMAKE)

Or use these commands to compile and link:

cl /Gd /D_X86_ /showIncludes /I%DDK_INC_PATH% /I%CRT_INC_PATH% /c main.c
link /verbose /nodefaultlib /subsystem:native /machine:X86 /entry:NtProcessStartup@4 C:\WinDDK\7600.16385.1\lib\win7\i386\nt.lib C:\WinDDK\7600.16385.1\lib\win7\i386\ntdllp.lib C:\WinDDK\7600.16385.1\lib\win7\i386\BufferOverflow.lib .\main.obj 

Note: This will build an x86 native executable. Change the appropriate bits if you want to build this for a different architecture.

Test

To test a native executable you have to execute it before the win32 subsystem is loaded. One common way to do it is to append the executable in the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute

Warning

If you do this however, you need to have an option to edit the registry hive of the target OS from another OS. Since you will not be able to boot the target OS anymore!

I did it on a VM where i could easily revert to a previous snapshot!

share|improve this answer

J, 14 bytes

2!:0'poweroff'

Works on Linux systems. 2!:0 executes the string in /bin/sh.

share|improve this answer

C++, 48 47 (Windows) 46 45 (Linux) bytes

Removed 1 byte thanks to Snowman

#include<cstdlib>
main(){system("shutdown/p");}

This should shutdown the system for windows

#include<cstdlib>
main(){system("poweroff");}

This should shutdown the system for Linux

share|improve this answer
    
do you need the ;? – RaisingAgent Jan 24 at 14:12
1  
@LliwTelracs Pretty sure it is "shutdown /p" and not "-p" and the space is not needed. – P. Ktinos Jan 24 at 14:14
    
The semicolon is required for proper c++ syntax, using a slash allows for a shorter answer for windows but makes it no longer work for linux. Although I added the wrong character for shutdown that is shared between windows and linux – LliwTelracs Jan 24 at 14:21
    
@LliwTelracs Although you can do whatever you want, I suggest abusing the 2nd rule and not caring about Linux functionality, since this is a code-golf and low amount of bytes is better. – P. Ktinos Jan 24 at 14:25
1  
#include<cstdlib> will shave off a byte. – Snowman Jan 24 at 18:14

Most Linux shells, 15 bytes

# echo o>/p*/*ger

It could be made to be 11 bytes long, if you happen to be in the /proc directory:

# echo o>*ger

This is very straightforward (has no side effects, like unmounting filesystems or killing processes) and rather brutal.

share|improve this answer
1  
Last time I tried wildcard expansion on redirect it generated a file with the wildcard in it despite a matching file existing. – Joshua Jan 25 at 18:57
4  
I believe you have to add "/proc/" to your byte count – zeppelin Jan 25 at 20:49
    
@Joshua It might be shell dependent. I actually tested it (with bash) on my computer :-) – Radovan Garabík Jan 25 at 21:12
1  
@Radovan Garabík - I don't think that is really valid. This is basically the same as implying that there is an alias "p=poweroff" (which is not "impossible" too) and claiming "p" to be a valid 1 byte solution. – zeppelin Jan 26 at 14:52
1  
But you can probably make it valid at expense of just 3 bytes, like this echo o>/p*/*ger – zeppelin Jan 26 at 15:40

AppleScript, 44 bytes

tell application "Finder"
shut down
end tell

I don't know how AppleScript syntax works or anything, so if anybody knows how to shorten this, please tell.

Also, I'm doing this on my phone at school ("hacking"), so I can't test it.

At 14 fewer bytes (thanks to kindall) you can say

tell app "Finder" to shut down
share|improve this answer
    
Someone came up with a shorter solution (with same program) a few hours after you (but posted it instead of commenting here) codegolf.stackexchange.com/a/107958/62824 – devRicher Jan 25 at 11:08
    
You can probably remove the indentation – Cyoce Jan 25 at 15:52
3  
tell app "Finder" to shut down should work, I believe (though the compilation may replace 'app' with 'application'). – kindall Jan 25 at 19:04

Node.js, 39 bytes

Linux

require('child_process').exec('init 0')
share|improve this answer

AHK, 19 15 bytes

Run,Shutdown -s

Works on windows only.

share|improve this answer

Mathematica on Windows 16 Bytes

Invoke the shell command with Run.

Run@"Shutdown/p"
share|improve this answer
    
Does this work on every OS, or a specific one? – Greg Martin Jan 24 at 18:18
1  
I'm sure a Linux person of any gender could! Perhaps "Mathematica on Windows" is more precise in the post itself? – Greg Martin Jan 24 at 20:20
3  
Lol. I use "guy" in the gender-neutral sense. slate.com/blogs/lexicon_valley/2016/02/10/… – Kelly Lowder Jan 24 at 22:56
1  
Although this term is still being debated, it is certainly the case that "guys" is not uniformly gender-neutral; and research definitely shows that gendered language has a harmful effect on STEM disciplines and the women participating in them. I believe it's important to bend over backwards to be inclusive with our language, since the gender equity problem is not solving itself. – Greg Martin Jan 25 at 1:04
1  
Linux shutdown code: shutdown +0 is the traditional way to do a shutdown and power off (using the tersest representations of the flags); shutdown with no arguments will delay 60 seconds then shut down. On recent systemd-based systems you're supposed to use systemctl halt or systemctl poweroff instead, but that's more bytes so who cares about that. Note that any of these commands require root permissions (as shutting down the system could cause data loss for anyone else logged in at the time, it's an action that affects other users, so you need enough permissions to be able to do that). – ais523 Jan 25 at 6:08

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.