shell脚本删除一天前的文件
今天公司要求我把服务器上的备份文件拷到内部服务器上,并且只要最新的,好吧,运维人员的理想目标是什么,就是能够让电脑做的事,决不自己来做.
系统:centos 5.9
环境:备份文件在/root/bak下,当然我是虚拟机上进行的测试
1.备份文件环境图

2.shell脚本内容:
运行脚本后的图

好了,可以看到脚本把今天以外的备份都删除了,如果你不想删除的话,那就改成下面的脚本:
好了,就这样吧.
系统:centos 5.9
环境:备份文件在/root/bak下,当然我是虚拟机上进行的测试
1.备份文件环境图

2.shell脚本内容:
#!/bin/bash location="/root/bak/" find $location -type f -mtime +1|xargs rm -f
运行脚本后的图

好了,可以看到脚本把今天以外的备份都删除了,如果你不想删除的话,那就改成下面的脚本:
#!/bin/bash location="/root/bak/" newfile="/root/newfile" file=$(find $location -type f -mtime -1) \cp $file $newfile
好了,就这样吧.
评论: