3 ms·
No OS is special here, nor is ZSH/bash... Tried this with bash on linux: $ touch -- -rf $ mkdir subdir1 $ touch subdir1/test1 $ rm * $ ls
by ninkendo 5y ago
No OS is special here, nor is ZSH/bash... Tried this with bash on linux:
$ touch -- -rf
$ mkdir subdir1
$ touch subdir1/test1
$ rm *
$ ls
-rf
$
With zsh it's almost the same, it just warns me first:
$ touch -- -rf
$ mkdir subdir1
$ touch subdir1/test1
$ rm *
zsh: sure you want to delete all 2 files in /path/to/test [yn]? y
$ ls
-rf
$
Since there was a file called -rf, `rm *` expands to `rm -rf subdir1`, and that's what it does. The actual file named -rf survives because -rf was interpreted as an option rather than a filename. It would only have been removed if I did `rm -rf -- *`.