如何使用 shell 在所有子目录中搜索文件,然后复制这些文件?

V 3*_*N 0 8 command-line

如何使用递归命令找到 *.mp3 文件,例如ls -R *.mp3在包含多个子目录的目录中,最后将这些文件复制到我选择的目录中。

谢谢您的支持。

hyt*_*omo 14

命令是:

find /path/to/directory -name "*.mp3" -exec cp {} /some/other/dir/ \;
Run Code Online (Sandbox Code Playgroud)

选择:

find /path/to/dir/ -name '*.mp3' | xargs cp -t /target/
Run Code Online (Sandbox Code Playgroud)

例子:

alex@MaD-pc:~/test$ ls
1  2  3
alex@MaD-pc:~/test$ ls 1 2 3
1:
1.txt  2.mp3  3.txt

2:
4.txt  5.mp3  6.txt

3:
alex@MaD-pc:~/test$ find . -name "*.mp3" -exec cp {} 3/ \;
alex@MaD-pc:~/test$ ls 3
2.mp3  5.mp3
Run Code Online (Sandbox Code Playgroud)

想要查询更多的信息:

man find
Run Code Online (Sandbox Code Playgroud)