Unlike many of the most basic Unix and Linux utilities, the rm command's name is not actually older than Unix itself. In Unix's predecessors, the Compatible Time Sharing System (CTSS) and Multics, the command used to remove files was called delete, which in Multics could optionally be abbreviated to dl. In Unix, the name became rm, probably to reflect the philosophical change from deleting files to removing the directory entries that linked to them.
Also part of Unix by the time of its First Edition manual (November 3, 1971) was the rmdir command to remove directories. Today the rmdir command just makes an rmdir() system call for each of its arguments and reports any errors. But in 1971 there was no rmdir() system call, so the rmdir program had to do all the work itself. It would make sure the directory being removed was empty and that its permissions were correct and then remove the ``.'' and ``..'' special links before unlinking the directory itself. This situation persisted until 1983, when the introduction of the new Fast File System in 4.2BSD made the creation and removal of directories the responsibility of the kernel.
The 1971 version of rm did not have any of the options that current versions have. It was also willing to remove read-only files, though the manual noted that it ``probably should ask.'' It was changed so that it did ask (as CTSS's delete had been in 1965) in a new version whose manual page was dated January 20, 1973, and which included these options:
rm -f | don't ask before removing read-only files |
rm -r | recursively remove subdirectories |
The way the rm -r option was implemented at that time, when rm encountered a directory among the files it was removing, it would cd (then called chdir) to that directory and start another instance of rm -r * to remove its contents. A version which did the recursion within a single rm process appeared in the Seventh Edition of Unix in 1979, which also introduced a new option:
rm -i | ask whether each file or directory should be removed |
This made it possible to type rm -i * to interactively remove selected files from a directory, including ones whose names had somehow been mangled to the point that they had become untypable. This feature had actually been needed much earlier, but prior to the Seventh Edition it had been done by a separate, now long abandoned program called dsw.
The name of dsw was more mysterious than any other command, even in this operating system known for its obscure names. The Sixth Edition manual taunted the curious with the note that ``the name dsw is a carryover from the ancient past. Its etymology is amusing.'' The First Edition had added ``... but the name is nonetheless ill-advised,'' but this disappeared from later manuals.
The speculation about what the name of dsw might really mean (delete s--t work? do svidaniya?) was put to an end when Dennis Ritchie revealed in a 1981 Usenet posting that the name had originally meant ``delete from switches.'' This was a reference to the toggle switches on the front panel of the PDP-7 computer that the earliest version of Unix ran on. (Some later hardware also had console switches, and the Third through Sixth Editions had a getcsw() system call that programs could use to find out what they were set to.)
To use the original dsw, you would set the front panel switches to a number and run dsw, which would then read that number of entries from the current directory, print on the terminal the name of the last one it had read, and crash itself, leaving a core dump. You could then, if you wanted, remove the file it had named by reexecuting the core file. When this awful user interface was replaced by a more reasonable one, the name remained until the entire program was replaced by rm -i.
At that point, the evolution of the rm command came, for the most part, to an end. A slightly altered version, dated April 1, 1981 and distributed with 4.2BSD, introduced an option terminator ``-'' to make it easier to remove files whose names started with a dash. For consistency with other commands, the POSIX standard changed this to ``--'' and made the capitalized option ``-R'' also remove directories recursively.