An undo facility is an essential component of most interactive applications. In current operating system shells, whether textual or graphical, such facilities are typically very poor. Algorithms are presented for adding a recovery mechanism to a shell which allows previous commands to be selectively undone and redone, and previous versions of files to be recovered. The recovery mechanism involves making the shell control resources in a more intelligent way. Programs are run under greater control, with the shell monitoring and analysing their resource requests. This provides better high level information to the shell and, for example, provides techniques to prevent foreign or untrustworthy programs from doing any damage, and to reduce problems with conflicting resource requests from concurrent programs. A prototype implementation called t brush has been constructed to investigate the convenience and natural feel of these facilities. It is command-independent and provided entirely at the user level. The idea is based on the interception of a particular class of system calls, using tracing facilities supported by many Unix operating systems. Recovery information required to implement selective undo is then stored according to the behaviour of the intercepted system calls. This doesn't involve any modification either to the kernel or to existing programs. The recovery mechanism maintains three components in the file system for purposes of selective undo and redo: a history file which consists of user-typed commands, a record file which keeps all file I/O requests made by system calls, and a personal directory in which old versions of files are located. These components enable the system to be brought back to any desired state. Users can reach all past copies of a file, without resorting to system administrator assistance. The system state is kept consistent during recovery, employing a conflict-detection mechanism that checks for the applicability of selective undo/redo. A shell environment with recovery facilities enables programs' interactions with the file system to be monitored very closely. Using this close monitoring, some Unix programs can be equipped with more sophisticated features. In this way, a \em make-like utility has been designed and implemented which provides automatic facilities in performing compilations of programs.