[Chapter 23] 23.6 A Faster Way to Remove Files Interactively
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:41:01Z

#

| Chapter 23 Removing Files |

## 23.6 A Faster Way to Remove Files Interactively

[The rm -i command asks you about each file, separately. The method in this article can give you the safety without the hassle of typing y as much. -JP]

Another approach, which I recommend, is that you create a new script or alias, and use that alias whenever you delete files. Call the alias del or Rm, for instance. This way, if you ever execute your special delete command when it doesn't exist, no harm is done - you just get an error. If you get into this habit, you can start making your delete script smarter. Here is one that asks you about each file if there are three or less files specified. For more than three files, it displays them all and asks you once if you wish to delete them all:

>     #!/bin/sh
>     case $# in
>     0)     echo "`basename $0`: you didn't say which file(s) to delete"; exit 1;;
>     [123]) /bin/rm -i "$@" ;;
>     *)     echo "$*"
>            echo do you want to delete these files\?
>            read a
>            case "$a" in
>            [yY]*) /bin/rm "$@" ;;
>            esac
>            ;;
>     esac

- BB

23.5 Remove Some, Leave Some |  | 23.7 Safer File Deletion in Some Directories