#退出程序函数
quit()
{
clear
echo "***************************************************"
echo "** Thank you for your use,Good bye! **"
echo "** If you have some good advice, **"
echo "** please contact me through email: **"
echo "** personalbest123@126.com **"
echo "** With your advice I'll do better! **"
exit 0
}
#欢迎函数
welcome()
{
clear
echo "***************************************************"
echo "** Welcome to this little program! **"
echo "** It helps you to do something about files. **"
echo "** Created by Gerrard **"
}
#查看指定目录下文件函数
display()
{
clear
echo "please input name of directory "
read MULU
cd $MULU
ls –l
}
#将指定文件打包函数
gettar()
{
clear
echo "please input the name of the file to be ziped"
read FILE
gzip $FILE
echo "File $FILE is ziped"
}
#将指定文件解压函数
unpack()
{
clear
UNPACK=1
echo -e "lease input the filename to be unpacked:\c"
read FILE
echo "Unpacking,Please wait!..."
if [ ${FILE##*.} = gz ] ; then
TEMP=${FILE%.*}
if [ ${TEMP##*.} = tar ] ; then
tar zxvf $FILE
UNPACK=$?
echo "This is a tar.gz package"
else
gunzip $FILE
UNPACK=$?
echo "This is a gz package"
fi
fi
if [ ${FILE##*.} = tar ] ; then
tar xvf $FILE
UNPACK=$?
echo "This is a tar package"
fi
if [ $UNPACK = 0 ] ; then
echo "Success!"
cat $FILE
else
echo "Maybe it is not a package or the package is damaged?"
fi
}
#删除指定文件函数
delete()
{
clear
echo -e "lease Enter the filename to be deleted:\c"
read FILE
echo "Deleting,Please wait!..."
gzip $FILE //先对文件进行压缩
mv $FILE.gz $HOME/dustbin //移动到回收站
echo "File $FILE is deleted !"
}
#找出含有指定关键字的文件
findkey()
{
while true;
do
echo "Input directory:"
read dir
if [ -e $dir ];then
echo -n "Input keyword: "
read "key"
grep -R "$key" $dir 2>/dev/null|less
else "The directory is not exist ! ";
fi
done
}
clear
while true
do
echo "======================================================"
echo "*** Fundenmental File Operation ***"
echo " 1-DISPLAY FILES IN DIRECTARY "
echo " 2-Pack A File "
echo " 3-Unpack A File "
echo " 4-Delete A File "
echo " 5-Find A File Containing A Keyword "
echo " 0-EXIT "
echo "======================================================"
echo -e "lease Enter a Choice(0--5):\c"
read CHOICE
case $CHOICE in
1) display;;
2) gettar;;
3) unpack;;
4) delete;;
5) findkey;;
0) quit;;
*) echo "Invalid Choice!Correct Choice is (0--5)"
sleep 4
clear;;
esac
done