移动多个文件子目录中(和/或multichar分隔符分割字符串)[庆典] [英] Moving multiple files in subdirectories (and/or splitting strings by multichar delimeter) [bash]

查看:140
本文介绍了移动多个文件子目录中(和/或multichar分隔符分割字符串)[庆典]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上,我有一堆的子文件夹所有在他们超过100个文件的文件夹。我想利用所有的MP3文件(实际上是通用的扩展,因为我必须与JPG做到这一点,等),并将其移动到一个新的文件夹中原来的目录。所以基本上的文件结构如下所示:

So basically, I have a folder with a bunch of subfolders all with over 100 files in them. I want to take all of the mp3 files (really generic extension since I'll have to do this with jpg, etc.) and move them to a new folder in the original directory. So basically the file structure looks like this:

/.../ DIR / recup1 / file1.mp3

/.../dir/recup1/file1.mp3

/.../ DIR / recup2 / file2.mp3

/.../dir/recup2/file2.mp3

...等。

和我希望它看起来是这样的:

and I want it to look like this:

/.../ DIR /音乐/ file1.mp3

/.../dir/music/file1.mp3

/.../ DIR /音乐/ file2.mp3

/.../dir/music/file2.mp3

...等。

我想我会使用沿着这些路线看上去bash脚本:

I figured I would use a bash script that looked along these lines:

#!/bin/bash
STR=`find ./ -type f -name \*.mp3`

FILES=(echo $STR | tr ".mp3 " "\n")

for x in $FILES
do
    echo "> [$x]"
done

我只是把它呼应了现在,但最终我会想使用 MV 来得到它的正确的文件夹。显然是因为TR将每个字符作为分隔符,这并不工作,虽然,所以如果你们有更好的想法我最好的AP preciate它。

I just have it echo for now, but eventually I would want to use mv to get it to the correct folder. Obviously this doesn't work though because tr sees each character as a delimiter, so if you guys have a better idea I'd appreciate it.

(仅供参考,我运行Ubuntu的上网本,所以如果有一个GUI的方式类似于Windows的搜索,我不反对使用它)

(FYI, I'm running netbook Ubuntu, so if there's a GUI way akin to Windows' search, I would not be against using it)

推荐答案

如果然后文件夹中存在的音乐以下应该工作 -

If the music folder exists then the following should work -

find /path/to/search -type f -iname "*.mp3" -exec mv {} path/to/music \;

A -exec命令必须以终止; (所以你通常需要键入 \\ ';'来避免外壳间pretion)或 + 。所不同的是,与; ,该命令每个文件调用一次,用 + ,它被称为只是少次为可能的(通常一次,但对于一个命令行的最大长度,所以它可能被分裂)与所有的文件名。

A -exec command must be terminated with a ; (so you usually need to type \; or ';' to avoid interpretion by the shell) or a +. The difference is that with ;, the command is called once per file, with +, it is called just as few times as possible (usually once, but there is a maximum length for a command line, so it might be split up) with all filenames.

这篇关于移动多个文件子目录中(和/或multichar分隔符分割字符串)[庆典]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆