[Question]
  [
(Just open 50 tabs in Google Chrome :D (just kidding, no you can't))
Shortest code for infinite disk I/O any language, C# example:
```
using System.IO;
namespace FileApp {
    static class Program {
        public static void Main() {
            do {
                File.WriteAllText("a", "a");
                File.Delete("a");
            } while (true);
        }
    }
}
```
You can't just fill the entire disk though, as then it would halt in the end and would be finite.
And you can't do reading only, infinite writing has to happen. (It has to kill my SSD after enough runtime.)
Get cracking! :)
  
[Answer]
## PowerShell v2+, 10 bytes
```
for(){1>1}
```
Simply loops infinitely with an empty `for` loop. Each iteration, we output the integer `1` (implicitly converted to a string) with the `>` [redirect operator](https://technet.microsoft.com/en-us/library/hh847746.aspx), which overwrites the file named `1` in the local directory.
[Answer]
# Pyth, 6 bytes
```
#.w]]0
```
Pyth's only file output command is `.w`. When called on a string, it writes that string to a file in append mode, which is no good for the purpose of this question. When called on a 2-d array, it writes the corresponding image to that file, overwriting the file contents. That's what this program does. The default file output name is `o.png`, so this program infinitely overwrites the file `o.png` with a 1-pixel white image. `#` is an infinite loop.
[Answer]
## DOS/Batch: 4 bytes
```
%0>x
```
This batch file will call itself (`%0`) and redirect (`>`) the output to a file called `x`. Since echo is on by default, this will output the path and command.
[Answer]
If you want a shorter (but more boring than my other one) answer:
# Bash, 5 bytes
```
>w;$0
```
I could make that shorter if there's a command (less than 3 bytes long) that writes something to disk I/O. Something like `sync` would work, but `sync` is 4 bytes üòõ
Note: this doesn't work when run straight from bash, only when put in a script and run as the script name. (i.e. `echo 'w>w;$0' > bomb; chmod 755 bomb; ./bomb`)
[Answer]
## Ruby, ~~22~~ 20 bytes
```
loop{open(?a,?w)<<1}
```
Repeatedly truncates and writes a `1` to the file `a`.
Thanks to [Ventero](https://codegolf.stackexchange.com/users/84/ventero) for 2 bytes!
[Answer]
# cmd, 14 bytes
```
:a
cd>1
goto a
```
Infinitly overwrites the file `1` with the string to the current directory
---
I'm new here:
Are *windows* new lines (`CR` `LF`) counted as two bytes?
[Answer]
# Bash + coreutils, 10
```
yes \>b|sh
```
Writes a continuous stream of `>b`, which is piped to `sh` for evaluation. `>b` simply truncates a file called `b` to zero bytes each time.
[Answer]
# Perl 5, ~~27~~ ~~32~~ 22 bytes
```
{{open my$h,'>o'}redo}
```
If simply changing the modification timestamp of a file suffices...
Quick explanation:
```
{ # Braces implicitly create/mark a loop.
    { # They also create closures, for `my` variables.
        open my $filehandle, '>', 'o';    # Writing to file "o".
        # close $filehandle;   # Called implicitly when
                               # variable gets destroyed.
    } # $filehandle gets destroyed because there are no references to it.
    redo; # ...the loop.
}
```
---
Previous solution (32 bytes): `{{open my$h,'>o';print$h 1}redo}`
**Edit:** `{open F,'O';print F 1;redo}` ← Didn't test the code before posting; now I had to correct it.
[Answer]
## PHP, ~~60 30 17 16~~ 15 bytes
Updated yet again as per @manatwork suggested:
```
while(!`cd>1`);
```
Also now tested. 
---
A bit of cheating 22 bytes:
~~while(exec('>1 dir'));~~
Earlier suggestion by @manatwork 30 bytes:
~~while(file\_put\_contents(1,1));~~
NOT TESTED (no php available on this computer) 43 bytes:
~~for($a=fopen(1,'w');fputs($a,1);fclose($a))~~
A golfed original 45 bytes:
~~$a=fopen(1,'w');while(fputs($a,1))rewind($a);~~
My first post here, joined because I just had to try this out: as long as file write succeeds, rewind file pointer to start.
---
~~Just can't get smaller than the file\_put\_contents().~~
[Answer]
# sh, 11 bytes
```
w>w;exec $0
```
Save this to a file without special characters, such as loop.sh, make it executable, and run it with `./loop.sh` or similar.
This writes the output of the command `w` to the file `w`, overwriting the previous value each time. Then, it replaces itself with a fresh version of the same program, so it can run infinitely.
[Answer]
# C, ~~95~~ ~~94~~ ~~93~~ ~~89~~ ~~78~~ ~~90~~ ~~89~~ ~~76~~ 75 bytes
```
#include<stdio.h>
main(){for(FILE*f=fopen("a","w");;fputc(0,f),fclose(f));}   
```
Again, `sudo watch -n1 lsof -p `pidof inf``  seems to say this is valid.
HOW DID I NOT SEE THAT SPACE D:<
Thanks [@Jens](https://codegolf.stackexchange.com/users/9533/jens) for shaving off 13 bytes :D
[Answer]
# Bash, 26 bytes
```
yes>y&while :;do rm y;done
```
If I were to expand this one-liner, I would get this:
```
yes > y &      # Write out infinitely to the file y in the current directory
while true     # Let's do something forever
do             # Here's what we're going to do
    rm y       # delete y
done           # That's all we're going to do
```
This can't exactly compete with the 10 byte PowerShell line, but it'll hold its own against the others. See my other answer for the 6 byte version.
[Answer]
# TI-BASIC, 12 bytes
```
While 1
Archive A
UnArchive A
End
```
Alternate solution by user [lirtosiast](https://codegolf.stackexchange.com/users/39328/lirtosiast) with the same size:
```
While 1
SetUpEditor
Archive ‚àü1
End
```
This will work on the TI-83+ and TI-84+ series of calculators.
*Yes, this also works if A is already archived or is not initialized at all at the start of the program! The program is only 12 bytes because of [tokenization](http://meta.codegolf.stackexchange.com/a/4764/52694)*.
[Answer]
# CPython 3.5, ~~33~~ 16 bytes
```
while 1:open("a")
```
Yes, really. :D
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 10 bytes
```
`1[]T3$Z#T
```
### Explanation
This is an infinite loop that writes number `1` to a file called `inout` in current directory, overwriting previous file's contents.
```
`       % do...while loop
  1     %   push number 1
  []    %   push empty array
  T     %   push "true"
  3$Z#  %   fwrite function. First input is file content. Second is file name;
        %   defaults to "inout" if empty. Third indicates that any previous
        %   file contents should be discarded
  T     %   push "true": loop condition 
        % implicitly end loop. Loop condition is "true", so the loop is infinite
```
[Answer]
## Haskell, 20 bytes
```
f=writeFile"b""a">>f
```
Write the string `"a"` to a file named `"b"` and repeat. `writeFile` overwrites the file if it exists. 
[Answer]
## JavaScript (Node.js), ~~43~~ 41 bytes
```
(c=x=>require("fs").writeFile("a",x,c))()
```
Writes `null` to a file named `a`, then repeat.
[Answer]
# ZSH, 14 bytes
```
for ((;;)) :>:
```
Zsh, unlike Bash and other Bourne-like shells, allows [loops without the `do ... done` fence](http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Alternate-Forms-For-Complex-Commands-1), provided the condition is suitably delimited.
Alternatively, with `while`:
```
while {} {:>:}
```
Note that `:` is a builtin. **You can't suspend this loop.**
The principle is the same as in [Digital Trauma's answer](https://codegolf.stackexchange.com/a/76831/31018) - nothing is written to the file, the IO is purely from creating and truncating the file.
[Answer]
# Rust, 84 Bytes
```
fn main(){loop{use std::io::Write;std::fs::File::create("a").unwrap().write(b"a");}}
```
`File::create` truncates an existing file, thus ensuring that we don't run out of disk space.
The used Compiler (1.9 Nightly) issues a warning about the unused result of `write(...)` but compiles nevertheless.
[Answer]
# C, 92 bytes
```
#include <stdio.h>
main(){for(FILE*f=fopen("a","w+");fprintf(f," "),!fclose(f);;);return 0;}
```
While it looks like you could save 1 byte by
```
  for(FILE*f=fopen("a","w+");fprintf(f," ")+fclose(f);;){}
```
the problem with that loop is that + doesn't give you the guaranteed order.
Or recursive - shouldn't overflow if the compiler properly implements tail recursion (f is in an explicit inner scope)
# 85 bytes
```
#include <stdio.h>
main(){{FILE*f=fopen("a","w+");fprintf(f," ");fclose(f);}main();}
```
[Answer]
# Mathematica, 14 bytes
```
For[,1>0,a>>a]
```
Repeatedly writes the string `"a"` to a file named `a` in the current directory, creating it if it doesn't exist.
[Answer]
## C, 40 bytes
```
main(){for(;;)write(open("a",1)," ",1);}
```
---
It will quickly run out of file descriptors, though; this can be overcome with:
## ~~45~~, 43 bytes
```
main(f){for(f=open("a",1);;)write(f,"",1);}
```
[Answer]
# C on amd64 Linux, 36 bytes (timestamp only), ~~52~~ 49 bytes (real disk activity)
I hard-code the `open(2)` flags, so this is not portable to other ABIs. Linux on other platforms likely uses the same `O_TRUNC`, etc., but other POSIX OSes may not.
**+4 bytes** to pass a correct permission arg to make sure the file is created with owner write access, see below. (This happens to work with gcc 5.2)
# somewhat-portable ANSI C, 38/51 bytes (timestamp only), 52/67 bytes (real disk activity)
Based on @Cat's answer, with a tip from @Jens.
The first number is for implementations where an `int` can hold `FILE *fopen()`'s return value, second number if we can't do that. On Linux, heap addresses happen to be in the low 32 bits of address space, so it works even without `-m32` or `-mx32`. (Declaring `void*fopen();` is shorter than `#include <stdio.h>`)
---
**Timestamp metadata I/O only**:
```
main(){for(;;)close(open("a",577));}   // Linux x86-64
//void*fopen();       // compile with -m32 or -mx32 or whatever, so an int holds a pointer.
main(){for(;;)fclose(fopen("a","w"));}
```
---
**Writing a byte, actually hitting the disk** on Linux 4.2.0 + XFS + `lazytime`:
```
main(){for(;write(open("a",577),"",1);close(3));}
```
`write` is the for-loop condition, which is fine since it always returns 1. `close` is the increment.
```
// semi-portable: storing a FILE* in an int.  Works on many systems
main(f){for(;f=fopen("a","w");fclose(f))fputc(0,f);}                 // 52 bytes
// Should be highly portable, except to systems that require prototypes for all functions.
void*f,*fopen();main(){for(;f=fopen("a","w");fclose(f))fputc(0,f);}   // 67 bytes
```
---
## Explanation of the non-portable version:
The file is created with random garbage permissions. With `gcc` 5.2, with `-O0` or `-O3`, it happens to include owner write permission, but this is not guaranteed. `0666` is decimal 438. **A 3rd arg to `open` would take another 4 bytes**. We're already hard-coding O\_TRUNC and so on, but this could break with a different compiler or libc on the same ABI.
We can't omit the 2nd arg to `open`, because the garbage value happens to include `O_EXCL`, and `O_TRUNC|O_APPEND`, so open fails with `EINVAL`.
---
We don't need to save the return value from `open()`. We assume it's `3`, because it always will be. Even if we start with fd 3 open, it will be closed after the first iteration. Worst-case, `open` keeps opening new fds until 3 is the last available file descriptor. So, up to the first 65531 `write()` calls could fail with `EBADF`, but will then work normally with every `open` creating fd = 3.
577 = 0x241 = `O_WRONLY|O_CREAT|O_TRUNC` on x86-64 Linux. Without `O_TRUNC`, the inode mod time and change time aren't updated, so a shorter arg isn't possible. `O_TRUNC` is still essential for the version that calls `write` to produce actual disk activity, not rewrite in place.
I see some answers that `open("a",1)`. O\_CREAT is required if `a` doesn't already exist. `O_CREAT` is defined as octal 0100 (64, 0x40) on Linux.
---
No resource leaks, so it can run forever. `strace` output:
```
open("a", O_WRONLY|O_CREAT|O_TRUNC, 03777762713526650) = 3
close(3)                                = 0
... repeating
```
or
```
open("a", O_WRONLY|O_CREAT|O_TRUNC, 01) = 3
write(3, "\0", 1)                       = 1   # This is the terminating 0 byte in the empty string we pass to write(2)
close(3)                                = 0
```
I got the decimal value of the `open` flags for this ABI using `strace -eraw=open` on my C++ version.
On a filesystem with the Linux `lazytime` mount option enabled, a change that only affects inode timestamps will only cause one write per 24 hours. With that mount option disabled, timestamp updating might be a viable way to wear out your SSD. (However, several other answers only do metadata I/O).
---
[Answer]
# Racket, 46 bytes
```
(do()(#f)(write-to-file'a"f"#:exists'replace))
```
[Answer]
# Factor, 73 bytes
```
USING: io.files io.encodings
[ 0 "a" utf8 set-file-contents ] [ t ] while
```
Sets the file contents to the nul byte forever.
[Answer]
# CBM BASIC 7.0, 9 bytes
```
0dS"a":rU
```
This program, when run, repeatedly saves itself to disk. Here's a more readable version which doesn't use BASIC keyword abbreviations:
```
0 dsave "a" : run
```
[Answer]
# Python, 32 bytes
```
while 1:open("a","w").write("b")
```
Note that if run on python 3, this will produce an infinite number of warnings. Also, it will probably run out of fds if run in a non-refcounting implementation.
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM) 15.0, 17 bytes (non-competing)
```
(‚ä¢‚ä£‚äÉ‚éïNPUT‚ä¢)‚ç£‚â¢'A'1
```
Chrome currently renders U+2262 wrong. The above line should look like `(‚ä¢‚ä£‚äÉ‚éïNPUT‚ä¢)‚ç£Ã∏‚â°'A'1`.
This is non-competing because version 15 has not been released yet.
Applies `‚ç£` the function `(‚ä¢‚ä£‚äÉ‚éïNPUT‚ä¢)` on `'A'1` until the input is changed (i.e. never):
`‚ä¢‚ä£‚äÉ‚éïNPUT‚ä¢` is a function train:
```
‚îå‚îÄ‚îº‚îÄ‚îÄ‚îÄ‚îê      
‚ä¢ ‚ä£ ‚îå‚îÄ‚îº‚îÄ‚îÄ‚îÄ‚îÄ‚îÄ‚îê
    ‚äÉ ‚éïNPUT ‚ä¢
```
The rightmost `‚ä¢` returns `'A'1` unmodified; this (filename, overwrite-flag) will be the right argument to `‚éïNPUT'.
'‚äÉ' returns the first element of `'A'1` (`'A'`); this is the data to be written.
Then `‚éïNPUT` is run, and reports how many bytes were written (2 or 3 depending on OS); this becomes the right argument to the `‚ä£`.
The leftmost `‚ä¢` again returns `'A'1` unmodified; this is the left argument to the `‚ä¢`.
`‚ä£` ignores its right argument and returns the left argument (`'A'1`), this becomes the new value fed to `‚ç£`.
Since the new value is identical to the old one, the operation is continued (forever).
[Answer]
# SmileBASIC, 12 bytes
```
SAVE"A
EXEC.
```
[Answer]
# vim text editor, 10 bytes
```
qa:w<enter>@aq@a
```
8 bytes if you do not could the execution command `@a`
]