Debian and its derivatives (and probably most other distributions) come with busybox
which is used in the initramfs
.
busybox
bundles most core command line utilities in a single executable.
You can temporarily symlink /bin/rm
to /bin/busybox
:
ln -s busybox /bin/rm
To get a working rm
(after which you can do your apt-get install --reinstall coreutils
).
That same method can be used for all the other utilities that busybox
includes. That list varies from one deployment to another. You can get the list with busybox --list
.
Note however that they are limited versions of the corresponding utilities. They sometimes support GNU extensions, but generally not and some of them will not even support all the standard/POSIX features (some features can be enabled/disabled at compile time).
Alternatively, you could use zsh
's builtin rm:
#! /bin/zsh -
zmodload zsh/files
rm "$@"
The zsh/files
module provides with a few additional builtin commands (rm
, mv
, ln
, mkdir
, rmdir
, chown
, chmod
, sync
). It's useful in this kind of situation or when you cannot fork more processes but do have an interactive zsh
running.
ksh93
also has a number of extra/optional commands buitin, but not rm
among them (basename
, chmod
, dirname
, getconf
, head
, mkdir
, logname
, cat
, cmp
, cut
, uname
, wc
, sync
). You can invoke them with:
command /opt/ast/bin/the-command
in a ksh93
script or invoke builtin the-command
for the the-command
builtin to be enabled and replace the external one.
ln -s /usr/lib/initramfs-tools/bin/busybox /bin/rm
(or/bin/busybox
, or extract it from an initrd)