试图清理我的id3标记,并在命令行上热爱id3v2 --但我一直只使用*.mp3通配符,并且希望探索是否有一种方法可以递归地使用它,这样我就可以批量处理所有的MP3s。似乎没有递归使用它的选项。
我敢肯定你们这些令人敬畏的命令行的人都知道一个很好的方法,但是我仍然在学习.
下面是我用暴力强制执行的命令:
id3v2 --remove-frame "COMM" *.mp3
id3v2 --remove-frame "PRIV" *.mp3
id3v2 -s *.mp3那么--有什么方法可以递归地这样做吗?这样我就可以把它作为我的音乐文件夹的根来运行了吗?重点:包括其他音频文件类型,并将上面的所有三个命令折叠成一个uber命令(我可以使用命令之间的;来实现这一点.对吧?)
发布于 2012-09-12 03:15:18
您应该能够在一行中做到这一点,如下所示:
find . -name '*.mp3' -execdir id3v2 --remove-frame "COMM" '{}' \; -execdir id3v2 --remove-frame "PRIV" '{}' \; -execdir id3v2 -s '{}' \;{}被替换为当前文件名匹配。将它们放入引号('')可以保护它们不受shell的影响。-execdir会一直运行,直到碰到分号为止,但是分号(;)需要从shell中转义,因此需要使用反斜杠(\)。这在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...由于您听起来似乎对此有点陌生,请注意:与往常一样,对于复杂的shell命令,请谨慎地运行它们,然后先在测试目录中尝试,以确保您了解将要发生的事情。伟大的权力带来了巨大的责任!
发布于 2012-09-12 03:06:49
快速解决方案是循环遍历所有子文件夹,并处理其中的所有文件:
find . -type d | while IFS= read -r d; do
cd "${d}"
id3v2 --remove-frame "COMM" *.mp3
id3v2 --remove-frame "PRIV" *.mp3
id3v2 -s *.mp3
cd -
done发布于 2012-09-13 00:21:39
我不使用id3v2,所以我不能确定,但是很有可能您可以将所有命令组合成一个:
id3v2 --remove-frame "COMM" --remove-frame "PRIV" -s *.mp3若要在子目录中的MP3文件中运行此命令,请运行
id3v2 --remove-frame "COMM" --remove-frame "PRIV" -s **/*.mp3**/*.mp3递归地匹配当前目录及其子目录中的.mp3文件。如果您的shell是zsh,那么**/就会开箱即用。如果您的shell是bash shopt -s globstar 4,则需要先运行≥(将这一行放在您的~/.bashrc中)。在ksh中,您需要运行set -o globstar (将其放在~/.kshrc中)。如果您有另一个shell,或者如果这个尝试失败了,因为消息告诉您命令行太大了,那么您必须使用下面的find方法(其他答案中给出的变体)。
递归地处理目录及其子目录中的文件的一种更复杂、更灵活和更可移植的方法是find命令:
find . -type f -name '*.mp3' -exec id3v2 --remove-frame "COMM" --remove-frame "PRIV" -s {} +执行-exec后的命令,将{} +位替换为匹配文件的路径。如果需要运行多个id3v2命令,请使用多个-exec指令:
find . -type f -name '*.mp3' -exec id3v2 --remove-frame "COMM" {} + -exec id3v2 --remove-frame "PRIV" {} + -exec id3v2 -s {} +https://unix.stackexchange.com/questions/47892
复制相似问题