rm -rf * :-(
ZXNet echo conference «zxnet.pc»
From Kirill Frolov → To All 31 May 2003
I applied the barmin name patch by accident :-(
It is not possible to restore anything with ext3fs :~-(
To avoid similar troubles in the future, I recommend:
0). Use the "blue panels"...
1). alias rm=trash in ~/.profile or ~/.bash_profile.
2). the below script in ~/bin/trash or somewhere else.
The script understands all /bin/rm options except -d.
The script should work with bash and BSD [a]sh,
maybe with zsh, not sure about other shells.
3). mkdir ~/.trash
4). export TRASHMAXSIZE=10000000 to ~/.bash_profile
sets the maximum size of a file or directory
with all attached files, which will
moved to ~/.trash (or to the directory specified
in the TRASHDIR variable) instead of deleting. Files
or larger directories will be deleted immediately,
but before this confirmation will always be requested.
5). the following commands should be placed in crontab
to clean out ~/.trash from time to time:
TRASHDIR=${TRASHDIR:="HOME/.trash"}
find /home/sysop/.trash/ -type f -size +1000k -ctime +1 -print0 | xargs -0 rm
2>/dev/null
find /home/sysop/.trash/ -ctime +7 -print0 | xargs -0 rm 2>/dev/null
6). An editor (Vim or Emacs) can be configured to trash backups
For Vim: set backup and set backupdir=~/.trash,.,/tmp,~/7). Debian users can install and configure more functional
libtrash and don't bother with my script.
#!/bin/sh
# send bug reports report to:
# version 0.1
TRASHDIR=${TRASHDIR:="$HOME/.trash"}
TRASHMAXSIZE=${TRASHMAXSIZE:=0}
opt_i=0; opt_r=0; opt_f=0; opt_v=0
opts() {
unset arg
args=:
for next in "$@"; do
case $arg in ?*) eval $arg='$next'; unset arg; args="${args}-"; continue;;
esac
case $next in
--) break;
;;
-h|--help|-help|--h|--he|--hel|-he|-hel)
echo "Usage: trash [OPTIONS]... FILE..."
echo "Move file(s) to trash can."
echo
echo "-f, --force ignore nonexistent files, never prompt"
echo "-i, --interactive prompt before any removal"
echo "-r, -R, --recursive remove the content of directories
recursively"
echo "-v, --verbose explain what is being done"
echo "-t, --trash specify trash can directory"
echo "-h, --help display this help and exit"
echo "--version output version information and exit"
echo
echo "See man page trash(1) for more information."
exit 0
;;
--version)
echo "trash version 0.0"
exit 0
;;
--interactive) opt_i=1; opt_f=0;; -r|-R|--recursive) opt_r=1;;
--force) opt_f=1; opt_i=0;;
--verbose) opt_v=1;;
--trash)
arg=TRASHDIR
;;
-*)
while { next=${next#?}; [ -n "$next" ]; };
do case ${next} in
i*) opt_i=1; opt_f=0;;
r*|R*) opt_r=1;;
f*) opt_f=1; opt_i=0;;
v*) opt_v=1;;
t*) case $next in t) arg=TRASHDIR;;
*) TRASHDIR=${next#?}
;; esac
next="-t"
break
;;
*)
while $((${#next}>1)); do next=${next%?}; done
echo "trash: invalid option -- `$next'"
echo "Try `trash --help' for more information."
exit 1
;; esac
done
;;
*)
args="${args}x"
continue
;; esac
args="${args}-"
done
case $arg in ?*)
echo "trash: option requires an argument: $next"
exit 1
;; esac
}
opts "$@"
unset rmopts mvopts
case $opt_f in 1) rmopts="$rmopts -f";; esac
case $opt_v in 1) rmopts="$rmopts -v"; mvopts="$mvopts -v";; esac
set -e
optend=no
for next in "$@"; do
args=${args#?}
case $args in -*) continue;; esac
[ -e "$next" ] || {
case $opt_f in 0)
echo "trash: cannot remove `$next': No such file or directory" >&2
;; esac
continue
}
[ $opt_r = 0 -a -d "$next" ] && {
case $opt_f in 0)
echo "trash: `$next' is a directory" >&2
;; esac
continue
}
case $opt_i in 1)
if [ -d "$next" ]; then echo "move directory `$next' to trash can?"
else echo "move file `$next' to trash can?"
fi
read a
case $a in y|Y);; *) continue;; esac
;; esac
if [ "$TRASHMAXSIZE" -eq 0 -o $(du -s "$next" | cut -f 1) -lt "$TRASHMAXSIZE"
]; then
eval mv $mvopts -- '$next' '$TRASHDIR'
else
echo "trash: `$next' cannot be moved to trash can"
echo "trash: REMOVE file or directory `$next'?"
read a
case $a in y|Y);; *) continue;; esac
eval rm $rmopts -- '$next' || true
fi
done
--
[ZX]