linux 脚本 替换,Shell文件自动替换脚本

文件替换脚本

使用方法:

./file-update.sh 文件名  大致路径(确定再那个路径下搜索)

#! /bin/bash

date1=`date +%Y%m%d%s`

date2=`date +%Y%m%d`

if [ -e /mnt/backup/$date2 ] ; then

:

else

mkdir -p /mnt/backup/$date2

fi

# backup-file

backup-file () {

echo "Do you want to backup this file? please select `echo "[y/n]"` "

read FILE

case $FILE in

y)

file1=$i

file2=$1

s=${file1##/*/}

r=${file2:=$s}

cp $i /mnt/backup/$date2 && echo "backup file ok" || echo "backup file fail" ;;

n)echo "NOT BACKUP file" ;;

*) backup-file ;;

esac

}

# update-file

update-file () {

echo "do you want to UPDATE this file ? please select `echo [y/n]`"

read FILE

case $FILE in

y)

file1=$i

file2=$1

s=${file1##/*/}

r=${file2:=$s}

cp $r $i && echo "update file ok" && rm -rf $r || echo "update file fail" ;;

n) echo "NOT UPDATE file" ;;

*) update-file ;;

esac

}

# find backup update update-file

Path=${2:?请输入替换文件大致路径}

select i in `find $Path -name $1`; do

backup-file

update-file

break

done

脚本演示:

4e099e46c558815fd3b72fd80321feda.png

执行过后会再/mnt/backup/创建一个时间的文件夹

并将所要替换文件移到上步新建的文件夹里

将新文件替换过去

最后删除新文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值