bash脚本,压缩和打包
1.给文件改名,并进行压缩
#!/bin/bash # -*- coding: utf-8 -*- ##给文件改名,并进行压缩 oldName="PriceAlarmServer" newName="PriceAlarmServerGnn" echo "oldName:"${oldName} echo "newName:"${newName} rm -rf ${newName} mkdir ${newName} cp ./${oldName} ./${newName}/${newName} tar -zcvf ${newName}.tgz ${newName} rm -rf ${newName}
2.打包压缩文件
#!/bin/bash # -*- coding: utf-8 -*- # 打包压缩文件 otherName="DataSyncClient_2" serverName="DataSyncClient" echo "other name:"${otherName} echo "server name:"${serverName} mkdir ${otherName} mv ${serverName} ${otherName}/ mv ${otherName}/ ${serverName} tar -zcvf ${serverName}.tgz ${serverName}/ echo "finish tar"
因为要创建的文件夹 和二进制文件同名,所以这里要先创建一个别名(othername)的文件,然后再做若干mv操作
这2个脚本,主要是列出bash下面字符串的一个用法。