【问题标题】:Shell script to find file older than 4 days and move用于查找超过 4 天的文件并移动的 Shell 脚本
【发布时间】:2017-06-22 15:13:05
【问题描述】:

如何在下面的代码中包含超过 4 天的文件?

尝试使用“-mtime +3”测试一些变体,但它给了我语法错误。用于查看文件是否退出并在超过 4 天时移动的功能。

#!/bin/ksh
FILE=test.txt
 if [ -f "$FILE" ]
   then mv "$FILE" "$FILE.old"
 fi

我搜索了很多线程,都使用 find 命令。

谢谢

【问题讨论】:

    标签: shell ksh


    【解决方案1】:

    find . -mtime +3 工作:

    $ cd -- "$(mktemp --directory)"
    $ touch --date='4 days ago' old
    $ touch new
    $ find . -mtime +3
    ./old
    

    你试过这种变化吗?如果有,你有哪个find

    【讨论】:

    • 感谢您的快速回复,它有助于解决棘手的部分,不胜感激。
    猜你喜欢
    • 1970-01-01
    • 2014-02-19
    • 2022-10-24
    • 1970-01-01
    • 2012-12-01
    • 2016-06-06
    • 2020-09-25
    • 1970-01-01
    相关资源
    最近更新 更多