如何使用BASH从文件名中删除特定字符 [英] How do I Remove Specific Characters From File Names Using BASH
本文介绍了如何使用BASH从文件名中删除特定字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要删除的文件中有很多文件具有共享模式.例如,我有文件"a_file000.tga"和"another_file000.tga".我想对那些文件进行操作,以从其名称中删除模式"000",从而得到新名称"a_file.tga"和"another_file.tga".
I have a lot of files that have a shared pattern in their name that I would like to remove. For example I have the files, "a_file000.tga" and "another_file000.tga". I would like to do an operation on those files that would remove the pattern "000" from their names resulting in the new names, "a_file.tga" and "another_file.tga".
推荐答案
尝试一下(这也适用于普通的Bourne sh
):
Try this (this works in plain old Bourne sh
as well):
for i in *000.tga
do
mv "$i" "`echo $i | sed 's/000//'`"
done
两个参数都用引号引起来,以支持文件名中的空格.
Both arguments are wrapped in quotes to support spaces in the filenames.
这篇关于如何使用BASH从文件名中删除特定字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文