Clone yourself!

Batch, 32 bytes

set/an=%1+1
copy %0 %n%
%0 %n%

Not using @ because there's no restriction on STDOUT. %1 defaults to the empty string, so n becomes 1 the first time and increments on every pass. Alternatively, this might work for 28 bytes, but I have no idea how random %random% actually is when used like this:

copy %0 %random%%random%
%0

Bash, 25, 16, 12, 11 bytes

EDITS:

  • Removed the newline (-1 byte), Added "Try It Online". Thanks @Dennis !
  • Use background job PID $! as the filename (will be reused every ~32k files, but that is now allowed), -4 bytes

Golfed

#!/bin/bash
$0&cp $0 $!

Explained

Re-spawns itself as a background job with &, before doing a copy, so each iteration will run under its own PID.

Uses the last job PID as the filename.

This can run infinitely (or until stopped) but will be reusing clone filenames approx. every ~32k iterations.

Could be a bit nasty to kill, but AFAIK is not against the rules.

Try It Online!


Zsh, 19 17 9 bytes

#!/bin/zsh
<$0>$$;$0

Per consensus on meta, the shebang is excluded from the byte count.

Try it online!

Note that TIO's forkbomb protection will kill the process after 113 files have been generated. It can easily generate 1000 files on a system without such conservative resource limits.