仅删除Linux中x天以前的目录(不是文件)

时间:2017-01-03 20:26:25

标签: linux bash shell find gnu-findutils

我正在尝试列出超过x天的目录(但不是文件)。我使用下面的命令来做到这一点。但它列出了目录和文件。任何人都可以帮我解决它吗?感谢。

find /path/to/base/dir/* -type d -ctime +10 -exec ls {} \;

2 个答案:

答案 0 :(得分:0)

试试这个

find /path/to/base/dir -maxdepth 1 -type d -ctime +10 -exec rm -r {} \;

答案 1 :(得分:0)

首先测试一切是否正常:

find /path/to/base/dir -type d -ctime +10 -exec ls -d {} \;

一切都好的时候:

find /path/to/base/dir -type d -ctime +10 -exec rm -fr {} \;

解释:

ls -d :  list directories themselves, not their contents
rm -f :  ignore nonexistent files and arguments, never prompt
相关问题