Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Linux中仅删除早于x天的目录(而不是文件)_Linux_Bash_Shell_Find_Gnu Findutils - Fatal编程技术网

在Linux中仅删除早于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 -

我试图列出超过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 -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{}
列出目录本身。GNU
find
有一个
-ls
操作,其行为类似于
ls-dils
查找
find
查找的内容。如果您只想让
ls-d
这样的输出显示它,您可以删除该操作,默认为
-print
,与
-exec ls-d{}相同