![](/img/trans.png)
[英]'find' all .log files under a directory, copy them to another directory named after their parent directory?
[英]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.