简体   繁体   English

bash:将父目录下所有匹配的文件递归移动到新目录下

[英]bash: recursively move all matched files in sub directory of parent to new sub directory

I've been attempting to recursively move all matched files in sub directory of parent to new sub directory. 我一直试图递归地将父目录下所有匹配的文件移动到新目录下。 The current structure is as follows (there are files other than wave files, they would need to be excluded): 当前结构如下(除了wave文件,还有其他文件,需要将它们排除在外):

.
├── a
│   ├── a.wav
│   └── media.dir
├── b
│   ├── b.wav
│   └── media.dir
├── c
│   ├── c.wav
│   └── media.dir
└── d
    ├── d.wav
    └── media.dir

And I'd like to move the wave file in each directory, to its corresponding media.dir. 我想将每个目录中的wave文件移动到其相应的media.dir中。 I have this so far, which is working for the match, but not the file move (when I echo instead of mv, I can confirm the file): 到目前为止,我有这个,它可以用于比赛,但不能移动文件(当我回声而不是mv时,我可以确认文件):

for dir in */
do
    find . -iname '*.wav' -print0 | xargs -0 -I{} mv '{}' "$dir/media.dir"
done

You probably want find "$dir" rather than find . 您可能想要find "$dir"而不是find . in your code: 在您的代码中:

for dir in */
do
    find "$dir" -iname '*.wav' -print0 | xargs -0 mv -t "$dir/media.dir"
done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一个 bash 脚本,用于解压 linux 中子目录中的所有文件 - A bash script to unrar all files in a sub directory in linux 对于所有子目录,将目录中指定扩展名的所有文件递归转换为pdf - Convert all files of a specified extension within a directory to pdf, recursively for all sub-directories 如何使用 PowerShell 递归搜索目录和子目录中的所有文件? - How to recursively search all files in a directory and sub-directories using PowerShell? 如何在父目录linux的子目录中查找和复制文件 - how to find and copy files in a sub directory from parent directory linux 查找字符串并替换目录和子目录中的所有文件 - Find a string and replace in all files inside a directory and sub-directory 将子文件夹从一个目录移动到另一目录 - move sub folder in one directory to another directory 在没有dos2unix的情况下递归转换目录和子目录中所有文件的所有EOL(dos-> unix) - Convert all EOL (dos->unix) of all files in a directory and sub-directories recursively without dos2unix linux将子文件夹中的文件移动到当前目录 - linux move files inside sub folder to current directory 在linux中,我怎样才能把zip具体的子目录改成自己的zip文件名,把父目录名和Z78E6221F6393D1356DZF2Z文件全部改成a393D1356DZF21的单目录? - In linux, how can I zip specific sub directories into their own zip files named parent directory name and output them all into a single directory? 在整个目录和子目录中递归地重命名文件名的一部分 - Rename a portion of a filename recursively throughout directory and sub directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM