[英]Scan For Multiple File Exentions and Copy To New Dir If Found
I am using Ubuntu
and I am needing to recursively search a directory and subs for any .mp4
, .mkv
, or .wav
files. 我正在使用
Ubuntu
并且我需要递归搜索目录和子目录以查找任何.mp4
, .mkv
或.wav
文件。 I saw that mmv
may be my best solution, but I can not get the syntax correct. 我看到
mmv
可能是我最好的解决方案,但是我无法获得正确的语法。 So how would I convert this to search for an array of file names, or would I just want to run 3 iterations for each file extension I am after? 那么,如何将其转换为搜索文件名数组,或者我只想为我追求的每个文件扩展名运行3次迭代?
I was using the tutorial here to write this, so please forgive me if I am way outta line find all m3 我在这里使用教程来编写,所以请原谅我找不到所有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 \;
With GNU bash 4: 使用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.globstar
:如果设置,则在路径名扩展上下文中使用的模式**将匹配所有文件以及零个或多个目录和子目录。 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.nullglob
:如果设置,bash允许不匹配任何文件的模式(请参阅路径名扩展)扩展为空字符串,而不是扩展为它们自己。
Replace -iname with -regex. 用-regex替换-iname。 Regex understands emacs regular expressions by default (but you can change this behaviour using -regextype):
Regex默认理解emacs正则表达式(但是您可以使用-regextype更改此行为):
find / -regex ".*\.mp4\|.*\.mkv\|.*\.wav" ...
Learn the power of reguar expressions, it will open a new universe of power! 了解常规表达的力量,它将打开一个新的力量世界!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.