rm alternative

페이지 정보

작성자 조희승 댓글 0건 조회 4,823회 작성일 12-08-17 15:04

본문

아래 스크립트를 /usr/bin/rf 로.....

#!/bin/bash
# Description: Replacement for rm. It moves files to trashbin directories
# which are stored on each mount point. trashbins can be different
# for each mountpoint. All trashbins are logged in TRASHBIN_LOG.
## TODO: fix the mv command to check for existance of same-named directories.
TRASH=.trash
TRASHBIN_LOG=/.trashbins
if [ $1 = "-init" ]; then
echo -init
rm -rfv `cat $TRASHBIN_LOG`
rm -rfv $TRASHBIN_LOG
exit
fi

## this is needed to reset TRASH variable for each argument
TRASH_DIR=$TRASH
## loop through all variables that are not options, and mv each to a trashbin.
while [ ! -z $1 ]; do
if [ ${1:0:1} = "-" ]; then
shift
else
## reset trash variable.
## this is important for deleteing multiple files
TRASH=$TRASH_DIR
## Get the Current mount point
MNT=`df "$1" | grep / | awk '{ for (i=6;i<=NF;i++) { printf " " $i } printf "\n" }'`
MNT=${MNT:1}
## Trash bins may be relocated depending on mount point.
## you may change these to your liking.
## TODO: this should be easier to edit, using variables

## heesn
TRASH="$MNT""$TRASH"
#if [ "$MNT" = "/" ]; then
# TRASH=/tmp/"$TRASH"
#elif [ "$MNT" = "/home" ]; then
# TRASH=/home/$USER/"$TRASH"
#else
# TRASH="$MNT"/"$TRASH"
#fi
## Test for the TRASH folder
if [ ! -d "$TRASH" ]; then
if mkdir "$TRASH" ; then
chmod 733 "$TRASH"
echo creating $TRASH
echo writing info to /.trashbins
echo $TRASH >> /.trashbins
else
echo ERROR: cannot create $TRASH
exit 1;
fi
fi

## Move each file to the trash, after updating time-stamp.
touch "$1"
mv -fv "$1" "$TRASH/"
shift
fi
done

댓글목록

등록된 댓글이 없습니다.