我所处的情况是,我的/tmp目录中至少有25,000到50,000个目录。我试图使用以下命令删除该目录中超过2天的目录。
find /path/to/tmp/* -type d -ctime +2 -delete但是我总是遇到一个错误,那就是参数列表太长了。如何具体限制被删除的目录的数量?我也尝试使用max纵深1选项,但这似乎不起作用。
发布于 2018-04-13 02:58:04
* glob会使shell展开所有目录名,并将它们传递给find。摆脱它,让find做工作而不是外壳。
find /path/to/tmp/ -mindepth 1 -type d -ctime +2 -delete-mindepth 1确保find只处理子目录,而不处理/path/to/tmp本身。
如果这些目录不是空的,则需要将-delete切换到rm -r。
find /path/to/tmp/ -mindepth 1 -type d -ctime +2 -exec rm -r {} +https://stackoverflow.com/questions/49808596
复制相似问题