如何在另一个目的地递归复制 *.txt 文件?

sti*_*ghy 3 linux

我需要将许多子目录中包含的所有 txt 文件复制到一个目录中。例子:

 MyDir
   Dir1
     1.txt
     2.txt
   Dir2
     a.txt
     b.txt
     e.jpg
   Dir3 
     f.txt
     k.txt
  MyDestination
Run Code Online (Sandbox Code Playgroud)

如何将所有 txt 复制到 MyDestination ?

use*_*517 6

尝试使用查找 ...

find /MyDir -name '*.txt' -exec cp -t /MyDestination "{}" +
Run Code Online (Sandbox Code Playgroud)

它将找到相关的txt文件并将它们分批传递给cp,让它将它们复制到MyDestination。