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