小编Sta*_*123的帖子

查找并删除超过 30 天的文件

我希望清除 30 天以上的用户文件。下面的 bash 脚本工作得很好。但是,我希望删除输出中显示的“没有这样的文件或目录”错误,因为我有自己的回声。有人可以帮忙吗?

代码:

if [[ $(find /h/$USER/*.txt -mtime +30) ]]
then
    find /h/$USER/*.txt -mtime +30 -print -exec rm -f {} \;
else
    echo "No txt files to del"
fi
Run Code Online (Sandbox Code Playgroud)

输出:

find: stat() error /h/username/*.txt: No such file or directory
No text files to del
Run Code Online (Sandbox Code Playgroud)

find files delete

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

delete ×1

files ×1

find ×1