查询定期清理文件基本命令(2)

1. 使用find删除test目录下3天前的

find /path/to/test -type f -mtime +3 -exec rm {} \;

2. 删除/opt目录下3天内的文件:
find /opt -type f -mtime -3 -exec rm {} \;

3. 删除正好第三天的文件:
find /opt -type f -mtime +2 -exec rm {} \;

4. 将/opt/test/a目录中的文件复制一份到/opt/test/目录下:
cp -r /opt/test/a /opt/test/

5. 创建目录/opt/test0:
mkdir /opt/test0

6. 在/opt/test0/目录下创建三个文件 a.mp4(5M), b.mp4(20M), c.mp4(80M):
touch /opt/test0/a.mp4
truncate -s 5M /opt/test0/a.mp4
touch /opt/test0/b.mp4
truncate -s 20M /opt/test0/b.mp4
touch /opt/test0/c.mp4
truncate -s 80M /opt/test0/c.mp4

7. 创建目录/opt/test0/b/:
mkdir /opt/test0/b

8. 将/opt/test0/中的文件复制一份到/opt/test0/b/目录中:
cp -r /opt/test0/* /opt/test0/b/

9. 查询并删除/opt/test0/目录中大于20M的文件:
find /opt/test0 -type f -size +20M -delete

10. 查询并删除/opt/test0/目录中小于20M的文件:
find /opt/test0 -type f -size -20M -delete

11. 查找并删除/opt/test0/目录中大小为20M的文件:
find /opt/test0 -type f -size 20M -delete

12. 将/opt/test0/b中的文件复制一份到/opt/test0中:
cp -r /opt/test0/b/* /opt/test0/

13. 将家目录中的bak.tar.gz文件上传到新主机的/opt目录中:

scp ~/bak.tar.gz user@new_host:/opt/
 

14. 将新主机的/etc/skel/目录下载到当前主机的/opt目录中:

scp user@new_host:/etc/skel /opt/
 

15. 设置计划任务,每周三将/etc/yum.repos.d/目录下的.repo文件压缩保存到tmp,并在文件名中添加时间戳:

# 创建一个脚本文件,例如 backup_repos.sh
echo '#!/bin/bash' > backup_repos.sh
echo 'tar -czvf /tmp/repos_backup_\$(date +%Y%m%d%H%M%S).tar.gz /etc/yum.repos.d/*.repo' >> backup_repos.sh
chmod +x backup_repos.sh

# 使用crontab设置定时任务
crontab -e
# 添加以下行到crontab文件中,表示每周三的凌晨1点执行备份任务
0 1 * * 3 /path/to/backup_repos.sh

  • 10
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值