Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.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 如何循环浏览多个文件夹和子文件夹并删除文件名从abc.txt和14天开始_Linux - Fatal编程技术网

Linux 如何循环浏览多个文件夹和子文件夹并删除文件名从abc.txt和14天开始

Linux 如何循环浏览多个文件夹和子文件夹并删除文件名从abc.txt和14天开始,linux,Linux,我有文件夹和子文件夹。我需要遍历每个文件夹和子文件夹,删除或移动以abc.txt开头的文件名,并将其移动到临时文件夹中。我的文件夹树结构是: 该文件可能位于文件夹或子文件夹中'abc.txt' 我使用了下面的代码,但没有工作 我使用下面的命令将文件夹路径放入list.txt文件 find $_filepath -type d >> folderpathlist.txt 我将路径列表传递给下面的代码,以搜索并删除文件或将文件移动到临时文件夹 find folderpathlist

我有文件夹和子文件夹。我需要遍历每个文件夹和子文件夹,删除或移动以abc.txt开头的文件名,并将其移动到临时文件夹中。我的文件夹树结构是:

该文件可能位于文件夹或子文件夹中'abc.txt'

我使用了下面的代码,但没有工作

  • 我使用下面的命令将文件夹路径放入list.txt文件

    find $_filepath -type d >> folderpathlist.txt
    
  • 我将路径列表传递给下面的代码,以搜索并删除文件或将文件移动到临时文件夹

    find folderpathlist.txt  -name "abc*" -mtime \+14 >>temp/test/
    

  • 如何实现此方案?

    您想查找文件:
    -type f

    以abc.txt开头:
    -name“abc.txt*”

    已经14天了:
    -mtime+14

    并将它们移动到目录。:
    -exec mv{}/tmp\
    要查看移动的内容:
    -print

    所以最后的命令是:

    find-键入f-名称“abc.txt*”-mtime+14-exec mv{}/tmp\-打印

    根据需要调整目录

    请注意,mtime是修改时间。因此,自上次对其进行修改以来,它已经使用了14天

    注2:
    -exec
    中的
    {}
    将替换为找到的每个文件名

    注3:
    \表示
    -exec


    注4:
    find
    仍将递归到子目录中。无需列出目录并再次循环。

    您可能应该使用
    -exec cp…
    -exec mv…
    。可能重复的、等。