繁体   English   中英

使用find删除缓存目录下的所有文件

[英]Remove all files under cache directory using find

我正在尝试使用find删除Web托管环境中缓存目录下的所有文件。

find /home/hosted -maxdepth 2 -type d -name "cache" -print -exec rm -rf "{}/*" \;

我已经尝试了几种方法,但是由于某种原因,find不会删除cache / *文件。 有人看到我想念的东西吗?

谢谢

-exec参数不会按预期扩展。 这是因为-exec直接调用execve(),因此*不会扩展到匹配目录中的所有文件。 如果要进行外壳扩展,则必须使用/bin/sh (或您选择的外壳)来给-exec喂,就像这样:

find /your/dir -name "cache" -type d -maxdepth 2 -print -exec sh -c "rm -f {}/*" \;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM