interactive rmdir : deletes non-empty directories
Nitin Sampat
nitin at ur-laser.uucp
Tue Dec 10 07:16:18 AEST 1985
Here is an interactive rmdir Bourne shell script which prompts
user for confirmation whenever he/she attempts to delete a non-empty
directory. I found this useful because I used to use the /bin/rm -r
to delete such directories. However, if I made a mistake with this command
it would delete all my files !! This shell script is the safe way out.
Also, its convenient.
Please test in a separate directory before use !! NO GAURENTEES
No Copyright but credit me out of courtesy if you don't mind !
To use shell this file ;
-------------------------CUT HERE----------------------------------------
#!/bin/sh
#FILE: rmdir
#AUTHOR: Nitin Sampat {seismo.allegra}!rochester!ur-laser!nitin.uucp
#DATE: Dec 7, 1985
#PURPOSE: To remove directories even if there are files
# in them but to interactively seek confirmation
# first.
#NOTE: If this file resides in /usr/you/bin read from
# this directory first. i.e Check your PATH !
# To execute , shell this file
#PUBLIC DOMAIN : No gaurentees !!!!!
case $# in
0) echo "Usage: rmdir dir";;
esac
for i
do if /bin/rmdir $i #first run original rmdir on argument(s)
then
echo "$i directory deleted " #rmdir successful
else #if original rmdir unsuccessful
if test -d $i #test if argument is a dir
then
echo -n "Do you really want to delete $i (y/n): " #prompt confirmation
read answer
case $answer in
y) /bin/rm -r $i #rmdir dir recursively
#if user confirms deletion
echo "$i directory deleted";;
*) ;;
esac
fi
fi
done
More information about the Comp.sources.unix
mailing list