扫描多个文件扩展名,如果找到则复制到新目录

Scan For Multiple File Exentions and Copy To New Dir If Found

我正在使用 Ubuntu,我需要递归搜索目录和子目录以查找任何 .mp4.mkv.wav 文件。我看到 mmv 可能是我最好的解决方案,但我无法获得正确的语法。那么我如何将其转换为搜索文件名数组,或者我只想 运行 对每个文件扩展名进行 3 次迭代?

我是用这里的教程写的,所以如果我跑题了请原谅我 find all m3

# find / -iname "*.mp4"  -type f -exec mv {} ./Downloads/Media Files \;

您可以使用 \(-o(或):

find / -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.wav" \) -exec mv {} ./Downloads/Media Files \;

使用 GNU bash 4:

shopt -s globstar nullglob
mv -v **/*.{mp4,mkv,wav} ./Downloads/Media Files

globstar: If set, the pattern ** used in a pathname expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match.

nullglob: If set, bash allows patterns which match no files (see Pathname Expansion) to expand to a null string, rather than themselves.

将 -iname 替换为 -regex。 Regex 默认理解 emacs 正则表达式(但您可以使用 -regextype 更改此行为):

find / -regex ".*\.mp4\|.*\.mkv\|.*\.wav" ...

学习正则表达式的力量,开启新的力量宇宙!