删除文件使用shell脚本在Unix中早于10天

编程入门 行业动态 更新时间:2024-10-28 18:35:09
本文介绍了删除文件使用shell脚本在Unix中早于10天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新来的shell脚本,谁能帮助?我想从当前日期的文件夹中删除脚本回10天。这些脚本如下:

I'm new to shell scripts, can anyone help? I want to delete scripts in a folder from the current date back to 10 days. The scripts looks like:

2012.11.21.09_33_52.script 2012.11.21.09_33_56.script 2012.11.21.09_33_59.script

该脚本将每10一天运行crontab,这就是为什么我需要的当前日期。

The script will run in every 10 day with Crontab, that's why I need the current date.

推荐答案

找到是这类任务的常用工具:

find is the common tool for this kind of task :

find ./my_dir/* -mtime +10 -type f -delete

说明

  • ./ MY_DIR 目录(用自己的替换)
  • -mtime +10 早于10天
  • 型的F 仅文件
  • -delete 毫不奇怪。删除前测试
  • ./my_dir your directory (replace with your own)
  • -mtime +10 older than 10 days
  • -type f only files
  • -delete no surprise. Remove it to test before

和照顾的 ./ MY_DIR 的存在是为了避免不良的惊喜!

And take care that ./my_dir exists to avoid bad surprises !

更多推荐

删除文件使用shell脚本在Unix中早于10天

本文发布于:2023-10-08 23:50:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1474112.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   早于   文件   shell   Unix

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!