Skip to content

Instantly share code, notes, and snippets.

@yongchun
Created December 26, 2013 04:55
Show Gist options
  • Save yongchun/8129971 to your computer and use it in GitHub Desktop.
Save yongchun/8129971 to your computer and use it in GitHub Desktop.
shell脚本,删除和移动文件
#!/bin/bash
#可以修改为工程所在的目录
user=yourhome
apphome=virtualinterface
appdir=/root/${user}/${apphome}
appdir_back=/root/${user}/${apphome}_back
appwar=/root/${user}/${apphome}.war
appwar_back=/root/${user}/${apphome}.war_back
#删除文件函数
function deleteFile()
{
echo -e "你要删除的文件或文件夹$1";
#判断工程的备份目录是否存在并具有执行权限,如果有就删除
if [ -x "$1" ]; then
rm -rf $1}
echo -e "删除成功"
return 1;
else
echo -e "文件或文件夹不存在"
return 0;
fi
}
#移动文件
function moveFile()
{
echo -e "将文件$1移动到$2"
if [ -x "${appdir}" ]; then
mv $1 $2
echo -e "移动成功"
else
echo -e "移动失败"
fi
}
deleteFile ${appdir_back};
moveFile ${appdir} ${appdir_back}
deleteFile ${appwar_back}
moveFile ${appwar} ${appwar_back}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment