在Linux中仅删除早于x天的目录(而不是文件)
我试图列出超过x天的目录(但不是文件)。我用下面的命令来做这件事。但是它列出了目录和文件。有人能帮我解决吗?谢谢在Linux中仅删除早于x天的目录(而不是文件),linux,bash,shell,find,gnu-findutils,Linux,Bash,Shell,Find,Gnu Findutils,我试图列出超过x天的目录(但不是文件)。我用下面的命令来做这件事。但是它列出了目录和文件。有人能帮我解决吗?谢谢 find /path/to/base/dir/* -type d -ctime +10 -exec ls {} \; 试试这个 find /path/to/base/dir -maxdepth 1 -type d -ctime +10 -exec rm -r {} \; 首先测试是否一切正常: find /path/to/base/dir -type d -ctime +10 -
find /path/to/base/dir/* -type d -ctime +10 -exec ls {} \;
试试这个
find /path/to/base/dir -maxdepth 1 -type d -ctime +10 -exec rm -r {} \;
首先测试是否一切正常:
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
它列出目录和文件,因为您对结果说的是
ls{}
。相反,请使用ls-d{}
列出目录本身。GNUfind
有一个-ls
操作,其行为类似于ls-dils
查找find
查找的内容。如果您只想让ls-d
这样的输出显示它,您可以删除该操作,默认为-print
,与-exec ls-d{}相同代码>