简体   繁体   English

扫描多个文件扩展名并复制到新目录(如果找到)

[英]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.

相关问题 PHP 7 --with-config-file-scan-dir不起作用 - php 7 --with-config-file-scan-dir not working 在当前目录中的所有目录和子目录中搜索与文件扩展名列表匹配的文件。 将这些文件复制到维护文件结构的新目录 - Search all dirs and subdirs in current dir for files that match list of file extensions. Copy those files to new dir maintaining file structure 使用新文件名从多个目录复制多个文件 - Copy multiple file from multiple directories with new filename 从多个文件复制一行并粘贴为新文件中的列 - Copy a row from multiple files and paste as column in a new file 需要帮助的shell脚本将多个目录复制并打包到tar中 - Need help for shell script to copy multiple dir and packing into tar 如何在 bash 中将文件复制到同一目录中但跨多个目录的具有新名称的新文件? - How to copy a file to a new file with a new name in same directory but across multiple directories in bash? 目录复制后找不到文件 - File not found after a directory copy 找不到QT_DIR - QT_DIR Not found 将匹配的正则表达式复制到新文件 - Copy matched regex to new file 如何使用cp linux将多个目录中的同名文件复制到新目录中 - How to copy a file with the same name from multiple directories into new directories using cp linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM