이 유틸리티는 셸 스크립트로 구현되어 있으며,
alias unrm="/home/<자기계정이름>/bin/recover"
와 같이 앨리어스를 지정해놓고 이용하면 편리하다. 물론 그러려면 아래의 셸 스크립트를 /home/<자기계정이름>/bin/recover에 설치해 두어야 할 것이다.
이 유틸리티는 unrm [-i] regex의 형식으로 사용하며, -i의 옵션을 줄 경우 파일을 복구할 때 마다 정말로 복구할 것인지를 사용자에게 물어본다. 복구할 파일의 이름은 정규표현식을 사용하여 작성하여야 한다는 약간의 불편함이 있긴 하다. 나중에 좀 더 개선할 여지가 있는 점이라고 하겠다.
#!/bin/bash
trashcan=~/trashcan
trashcan_cnt=~/trashcan/count
trashcan_idx=~/trashcan/index
interactive=0
#
# process interactive option
#
for file in $@
do
if [ "${file:0:1}" == "-" ]
then
if [ "${file:1:1}" == "i" ]
then
interactive=1
fi
else
only_file+="$file "
fi
done
#
# recover
#
for file in $only_file
do
egrep $file $trashcan_idx | sort -r -k2 -k1 | cut -f1-4 | uniq -f1 > $trashcan/tmp1
cat $trashcan/tmp1 | awk '{print "mv ~/trashcan/"$1"/"$3 ,$2}' > $trashcan/tmp2
idx=0;
while read line
do
lines[$idx]=$line
let idx=idx+1
done < $trashcan/tmp2
idx2=0;
while [ $idx2 -lt $idx ]
do
if [ $interactive -eq 1 ]
then
read -s -n1 -p "If you want to execute '${lines[$idx2]}', press [y/Y] " var
echo $var;
if [[ "$var" == "Y" || "$var" == "y" ]]
then
echo 'recovery is in progress'
eval ${lines[$idx2]}
fi
else
eval ${lines[$idx2]}
fi
let idx2=idx2+1
done
cat $trashcan/tmp1 $trashcan_idx | sort | uniq -u > $trashcan/tmp3
mv $trashcan/tmp3 $trashcan_idx
\rm -f $trashcan/tmp?
done
소중한 의견, 감사합니다. ^^