gpt4 book ai didi

bash - 如何使用 find 和 rm 命令删除文件?

转载 作者:行者123 更新时间:2023-11-29 08:54:13 24 4
gpt4 key购买 nike

find -mmin -19 -exec rm '{}'\;

它会首先找到修改过的文件,然后删除它们。但它给了我如下错误,查找:缺少 `-exec' 的参数

还尝试了各种组合,例如,

find -mmin -19 -exec rm '{}';\
find -mmin -19 -exec rm '{}'/;

最佳答案

命令和 \; 之间需要空格

find -mmin -19 -exec rm {} \;

find 已经提供了-delete 选项,所以你不需要使用-exec rm ..:

find -mmin -19 -delete

-delete

Delete files; true if removal succeeded. If the removal failed, an error message is issued. If -delete fails, find's exit status will be nonzero (when it eventually exits). Use of -delete automatically turns on the -depth option.

Warnings: Don't forget that the find command line is evaluated as an expression, so putting -delete first will make find try to delete everything below the starting points you specified. When testing a find command line that you later intend to use with -delete, you should explicitly specify -depth in order to avoid later surprises. Because -delete implies -depth, you cannot usefully use -prune and -delete together.

关于bash - 如何使用 find 和 rm 命令删除文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31769658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com