我希望清除 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)