我有一个目录,其中包含未知数量的子目录和未知级别的子*目录。如何将所有具有相同后缀的文件复制到一个新目录?
例如从这个目录:
> some-dir
>> foo-subdir
>>> bar-sudsubdir
>>>> file-adx.txt
>> foobar-subdir
>>> file-kiv.txt
将所有 *.txt 文件移动到:
> new-dir
>> file-adx.txt
>> file-kiv.txt
最佳答案
一种选择是使用find
:
find some-dir -type f -name "*.txt" -exec cp \{\} new-dir \;
find some-dir -type f -name "*.txt"
会在目录 some-dir
中找到 *.txt
文件. -exec
选项为每个由 {}
表示的匹配文件构建一个命令行(例如 cp file new.txt
)。
关于linux - 如何将所有具有相同后缀的文件复制到另一个目录? - Unix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17343069/