home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 23.5 Remove Some, Leave Some Chapter 23
Removing Files
Next: 23.7 Safer File Deletion in Some Directories
 

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


Previous: 23.5 Remove Some, Leave Some UNIX Power Tools Next: 23.7 Safer File Deletion in Some Directories
23.5 Remove Some, Leave Some Book Index 23.7 Safer File Deletion in Some Directories

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System