我在一个文件夹中备份了所有 mp3 文件。
会不会有一个 bash 命令来自动移动他们自己的即时创建的乐队专辑标题目录中的所有文件?
正如您在图片中看到的,破折号之前的第一个单词是艺术家姓名,然后是专辑名称,然后是歌曲名称。
示例:艺术家或乐队 - 专辑名称 - 歌曲名称.mp3。
所以最后,文件将处于以下层次结构中。
Artist or band1/
album title1/
name of song.mp3
album title2/
name of song.mp3
Artist or band2/
album title1/
name of song.mp3
等等。
最佳答案
我不知道直接执行此操作的命令,但这是我解决此问题的方法(使用 Perl):
perl -MFile::Path -we 'for my $file (glob "*.mp3") { my ($artist, $album, $title) = split / - /, $file, 3; mkpath "$artist/$album"; my $new = "$artist/$album/$title"; rename $file, $new or warn "$file -> $new: $!\n"; }'
或稍微更具可读性:
perl -MFile::Path -we '
for my $file (glob "*.mp3") {
my ($artist, $album, $title) = split / - /, $file, 3;
mkpath "$artist/$album";
my $new = "$artist/$album/$title";
rename $file, $new or die "$file -> $new: $!\n";
}'
关于linux - 将 mp3 文件从一个目录移动到按艺术家、专辑、歌曲名称分开的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37902910/