bash 中匹配空格
我想删除由itunes创建的重复文件,这些文件都以“1.mp3”结尾。我已经接近匹配,但我不知道如何匹配空间。有人可以编写一个命令来从当前目录递归删除这些文件吗?
I want to delete duplicate files made by itunes, which all end in " 1.mp3". I've come close to matching but I don't know how to match the space. Can somebody writeup a command to recursively delete those files from the current directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您想要浏览 iTunes 收藏并删除 Nickelback 的 If I care 1.mp3,但前提是 Nickelback 原始 MP3 If I care.mp3 仍然存在。正确的?
嘿,你的音乐品味取决于你...
这应该可以解决问题:
我找到所有重复项(以 space-1.mp3 结尾的歌曲)并将它们传送到
while
语句。${word%filter}
语法表示获取$word
并从右侧删除全局表达式filter
。因此,${file% 1.mp3}
是不带1.mp3
后缀的文件名。现在,If I care 1.mp3
变为If I care
。因此,我们需要重新添加.mp3
后缀。因此${file%1.mp3}.mp3
。这为我们提供了文件的原始名称。现在,我们使用 -e 测试来检查该文件是否存在。如果是这样,我们可以删除该歌曲的 space-1.mp3 版本。
我运行了一些基本测试,但我建议您先尝试一下(也许将
rm $file
更改为echo Removing file $file
首先并验证这些文件是否具有原始文件)。You want to go through your iTunes collection and remove Nickelback's If I care 1.mp3 but, only if the Nickelback original MP3, If I care.mp3, still exist. Right?
Hey, your musical tastes are up to you...
This should do the trick:
I am finding all the duplicates (songs that end in space-1.mp3) and piping them to the
while
statement.The
${word%filter}
syntax says take the$word
and remove from the right hand side the glob expressionfilter
. Thus,${file% 1.mp3}
is the name of the file sans the1.mp3
suffix. Now,If I care 1.mp3
becomesIf I care
. We, therefore need to add the.mp3
suffix back on. Thus${file% 1.mp3}.mp3
. This gives us the original name of the file.Now, we use
-e
test to check if that file exists. If it does, we can delete the space-1.mp3 version of the song.I ran some basic tests, but I suggest you try it out first (maybe change
rm $file
toecho Removing file $file
first and verifying that those files do have the original).听起来像是
find
的工作!Sounds like a job for
find
!与其他解决方案类似,但会检查不带“1”后缀的文件是否确实存在,因此不会意外删除名称以“1”结尾的歌曲。
Similar to other solutions, but checks that the file without the " 1" suffix really exists, so it does not accidentaly remove songs whose names end in " 1".
快点:
Faster:
kbyrd 提到的对我来说是最好的方法,因为 -print0 和 -0 组合。
which kbyrd mentions is the best way according to me because of the -print0 and -0 combination because.