[Question]
  [
If a compiled language is used, the program must delete the compiled executable (but need not delete the source file). If an interpreted language is used, the program must delete the source file.
My opening bid:
## Python (29 characters)
```
import os;os.remove(__file__)
```
Edit: to prevent solutions like [rm -rf /](https://codegolf.stackexchange.com/a/11797/14091), the program must not delete anything except the executable or source file.
```
html,body{margin:0;padding:0;height:100%;overflow:hidden}
```
```
 <iframe src="https://xmikee1.github.io/ppcg-leaderboard/?id=19355" width="100%" height="100%" style="border:none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe>
```
  
[Answer]
## Bash script (7 characters, 7 bytes)
```
rm "$0"
```
[Answer]
# Unix? (9):
```
#!/bin/rm
```
A classic. Uses `rm` as interpreter, for instant self-deletion. Not the very shortest though.
[Answer]
## Batch - 6 bytes
```
Del %0
```
Pretty simple. Note: Works even if the name contains spaces.
[Answer]
# Ruby, 14 characters
```
File.delete $0
```
`$0` is a special global variable that contains the name of the currently running script.
[Answer]
# BASIC-80 / BASICA / GW-BASIC / IBM BASIC / Commodore 64 BASIC / Vintage BASIC / Commodore LCD BASIC / Atari BASIC \*
# 5 bytes
```
1 NEW
```
Well, that's about as simple as it gets. `NEW` creates a new program, so putting this anywhere in your program will delete it.
Proof of concept on IBM BASIC (putting `NEW` on line 40 for clarity):
[![](https://i.stack.imgur.com/uyjCu.png)](https://i.stack.imgur.com/uyjCu.png)
\* Yeah, I listed every old BASIC version I've tested this in (or pretty much ever used)
[Answer]
# PHP, 17 characters
```
unlink(__FILE__);
```
[Answer]
**PowerShell (32)**
```
del $MyInvocation.MyCommand.Name
```
[Answer]
**Perl 5 (8 characters)**
```
unlink$0
```
`$0` is the script name, and `unlink` removes it. Normally, you'd at least add a space in between for readability.
[Answer]
**C# (112)**
```
Process.Start("cmd.exe","/C choice /C Y /N /D Y /T 3 & Del " + Application.ExecutablePath);
Application.Exit();
```
Shamelessly stolen from <http://www.codeproject.com/Articles/31454/How-To-Make-Your-Application-Delete-Itself-Immedia>
[Answer]
### R, 26 characters
```
unlink(sys.frame(1)$ofile)
```
[Answer]
# k (8)
```
~-1!.z.f
```
Or the q equivalent for 14:
```
hdel hsym .z.f
```
[Answer]
# Python, 18
```
open(__file__,'w')
```
Opens itsself in write-only mode, erasing itself.
[Answer]
# Node.js - 22 chars
```
fs.unlink(__filename);
```
[Answer]
# Julia, 13 bytes
```
rm(@__FILE__)
```
Simple. But longer. :P
[Answer]
# Vitsy + bash, 8 bytes
```
iG' mr',
iG       Get the name of the use declaration at the top item (-1) (returns the current one)
  ' mr'  Concatenate "rm " to the front of it.
       , Execute via shell.
```
[Answer]
# Mathematica, 29 bytes
```
DeleteFile@NotebookFileName[]
```
[Answer]
# Lua, 17 bytes
```
os.remove(arg[0])
```
This actually only works if you run the program by typing out the full filepath, i.e.  
`lua ~/Scripts/removeself.lua` would work, but `lua removeself.lua` would not, assuming a filename of `removeself.lua` and a current working directory of `~/Scripts`.
As far as I know, there's no way to find the actual filepath of a script, just the arguments passed to it. I do know about `debug.getinfo(1).source`, but in my testing that game exactly the same results as `arg[0]`. If anyone knows of a way to find the filepath, please let me know.
[Answer]
# JS, 37 bytes
```
document.documentElement.innerHTML=""
```
Does this count? It kills javascript on the page
[Answer]
# tcl, 18
```
file delete $argv0
```
[demo](http://www.tutorialspoint.com/execute_tcl_online.php?PID=0Bw_CjBb95KQMY2M1TWNWWWQycGM) — **ATTENTION:** It is only a one time demo! Only the first time it will be runnable. Please reserve it to the question's original poster.
To try: press the `Execute` button. The green area will not report any error. After that, any subsequent clicks on the `Execute` button will result on a `not found` error!
[Answer]
# [shortC](//github.com/aaronryank/shortC), 10 bytes
```
Aremove(*@
```
How it works:
```
A           main function
 remove(    delete file specified in next string
        *@  program name
```
Equivalent C program:
```
int main(int argc, char **argv){remove(*argv);}
```
[Answer]
## C, 32 bytes
```
main(c,v)char**v;{remove(v[0]);}
```
[Answer]
# JavaScript (ES6), 13 bytes
```
f=_=>delete f
```
---
## Try It
Logs the source of `f`, calls `f` (which deletes `f`), tries to log `f` again but throws an error because `f` is now undefined.
```
f=_=>delete f
console.log(f)
f()
console.log(f)
```
[Answer]
# 8086/8088 machine code, 1 byte
```
aa    stosb
```
Assumptions:
* The registers CS, IP, ES, DI, and AL are all initially 0.
* This code is placed at address 0.
The `stosb` instruction stores the byte in the AL register at the memory location pointed to by ES and DI, then increments or decrements DI. In this case, it stores the byte 0 at the memory address 0, which happens to be where the instruction itself is.
Granted, this program doesn't delete a file or anything. But if you manage to get your hands on an 8086 processor, poke this program into memory, and run it, it will in fact overwrite itself.
[Answer]
# VBA, ~~69~~ 62 Bytes
Subroutine that takes no input and deletes itself.
Requires that the code below be the first line in the active code pane, and that VBA has trusted access to the VBE Project model.
```
Sub A:Parent.VBE.CodePanes(1).CodeModule.DeleteLines 1:End Sub
```
-2 bytes for replacing `ActiveCodePane` with with `CodePane(1)`
-5 bytes for replacing `Application` with `Parent`
[Answer]
## PowerShell v3 - 17
```
ri $PSCommandPath
```
[Answer]
# Julia - 25 bytes
Write this into a file, and then include the file with `include("<filename here>")` and run `f()`:
```
f()=rm(functionloc(f)[1])
```
This is, obviously, a function - I'm not sure how one would go about detecting the file name of a file being run directly (as an include statement without a function definition in it).
[Answer]
## C++, 137 bytes.
Works most of the time on windows 
```
#include <stdlib.h> 
#include <string>
int main(int, char*v[]){char c[99];sprintf(c,"start cmd /C del \"%s\"/Q", *v);return system(c);}
```
## C, 90 bytes
```
void main(int n,char**v){char c[99];sprintf(c,"start cmd /C del \"%s\"/Q", *v);system(c);} 
```
[Answer]
## MATLAB, 36 bytes
```
delete([mfilename('fullpath'),'.m'])
```
Save the above code as an m-file following Matlab's filename guidelines.
[Answer]
# Nodejs, 32 bytes
```
require("fs").unlink(__filename)
```
[Answer]
# T-SQL, 28 bytes
```
CREATE PROC d AS DROP PROC d
```
It just drops/removes the procedure and the code when executing itself. Usage:
```
EXECUTE d
```
]