Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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 在特定目录路径中查找文件_Linux_Bash - Fatal编程技术网

Linux 在特定目录路径中查找文件

Linux 在特定目录路径中查找文件,linux,bash,Linux,Bash,我试图设置一个cron作业来删除服务器上特定路径中生成的旧文件 我的问题是,我只想清理命名的cleanupdir中的旧文件,该文件在许多父目录中重复 写出所有这些内容非常耗时: find ~/dir\ 1/cleanupdir/ -name *.htm -mtime +7 -delete find ~/dir\ 2/cleanupdir/ -name *.htm -mtime +7 -delete find ~/dir\ 3/cleanupdir/ -name *.htm -mtime +7 -

我试图设置一个cron作业来删除服务器上特定路径中生成的旧文件

我的问题是,我只想清理命名的
cleanupdir
中的旧文件,该文件在许多父目录中重复

写出所有这些内容非常耗时:

find ~/dir\ 1/cleanupdir/ -name *.htm -mtime +7 -delete
find ~/dir\ 2/cleanupdir/ -name *.htm -mtime +7 -delete
find ~/dir\ 3/cleanupdir/ -name *.htm -mtime +7 -delete
...
运行此操作将删除许多我要保留的文件

find ~/ -name *.htm -mtime +7 -delete
理想情况下,我希望路径有一个通配符,这样我就可以运行了

find ~/*/cleanupdir/ -name *.htm -mtime +7 -delete
但这似乎没有得到支持

我的另一个尝试是

find ~/ *.htm -mtime +7 | grep /cleanupdir/ | xargs rm
但是,
dir1
etc目录中的空格意味着这不起作用


无论是使用bash脚本,还是使用find的巧妙单行代码,我都觉得很有用,因为我说过这是专门为cronjob设计的。

find~-name“*.htm”-wholename“*/cleanupdir/*”-mtime+7-delete

你上次的尝试看起来不错,除非您需要引用通配符,以便shell不会将其扩展到当前目录中的
*.htm
文件列表

find ~/*/cleanupdir/ -name '*.htm' -mtime +7 -delete

请提供更多信息,不仅是关于您要删除的文件,还包括您要保留的文件。
find~/*/cleanupdir
如果使用完整路径
find/home/user/*/cleanupdir
编写,可能会更好。Stack Overflow是一个用于编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参见帮助中心中的。也许或者会是一个更好的提问的地方。