id3v2 在命令行中递归使用?

cho*_*how 6 command-line shell recursive files

试图清理我的 id3 标签,我喜欢在命令行上使用 id3v2 - 但我一直只使用 *.mp3 通配符并想探索是否有一种方法可以递归使用它,以便我可以批量处理所有我的 MP3。似乎没有递归使用它的选项。

我很确定你们所有很棒的命令行人都知道这样做的好方法,但我仍在学习它的方法......

这是我使用别名来暴力破解它的命令:

id3v2 --remove-frame "COMM" *.mp3
id3v2 --remove-frame "PRIV" *.mp3
id3v2 -s *.mp3
Run Code Online (Sandbox Code Playgroud)

那么 - 有没有办法递归地执行此操作,以便我可以在音乐文件夹的根目录中运行它?肉汁点:包括其他音频文件类型并将上面的所有三个命令折叠成一个超级命令(我可以用;两个命令来做到这一点......对吗?)

ire*_*ses 6

您应该能够在一行中完成此操作,如下所示:

find . -name '*.mp3' -execdir id3v2 --remove-frame "COMM" '{}' \; -execdir id3v2 --remove-frame "PRIV" '{}' \; -execdir id3v2 -s '{}' \;
Run Code Online (Sandbox Code Playgroud)

{} 替换当前文件名匹配。将它们放在引号 ( '') 中可以保护它们免受 shell 的影响。的-execdir运行,直到它碰到分号,但分号(;)需要从外壳逸出,因此,使用反斜线的(\)。这在手册find 页中都有描述:

-exec command ;
      Execute  command;  true  if 0 status is returned.  All following
      arguments to find are taken to be arguments to the command until
      an  argument  consisting of `;' is encountered.  The string `{}'
      is replaced by the current file name being processed  everywhere
      it occurs in the arguments to the command, not just in arguments
      where it is alone, as in some versions of find. 
-execdir command {} +
      Like -exec, but the specified command is run from the  subdirec?
      tory  containing  the  matched  file,  which is not normally the
      directory in which you started find.  This a  much  more  secure
      method  for invoking commands...
Run Code Online (Sandbox Code Playgroud)

由于您听起来对此有点陌生,因此请注意:与复杂的 shell 命令一样,请谨慎运行它们,并首先在测试目录中尝试,以确保您了解将要发生的情况。拥有权利的同时也被赋予了重大的责任!