bash 查找,仅删除文件 - 参数顺序 [英] bash find, only delete files - order of arguments
本文介绍了bash 查找,仅删除文件 - 参数顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设今天是 4 月 8 日,我在 bash 中执行以下操作.
Say today is April 8th and I execute the following in bash.
cd /tmp
mkdir hello
touch -d 2015-04-01 hello
然后,假设我想删除/tmp 中所有超过一天的文件,但不是目录,我执行以下操作:
Then, say I want to delete all files in /tmp that are older than one day, but NOT directories and I execute this:
find /tmp -mtime +1 -delete -type f
如果不是文件,为什么目录hello"会被删除?
Why is directory "hello" deleted if it's not a file?
谢谢!
推荐答案
find命令按顺序执行表达式.由于 -delete
在 -type
之前,因此永远不会到达 -type
.试试:
The find command executes the expression in order. Since -delete
is before -type
, -type
is never reached. Try:
find /tmp -mtime +1 -type f -delete
这篇关于bash 查找,仅删除文件 - 参数顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文