重命名多个文件,同时在Linux上保留相同的扩展名 [英] Rename multiple files while keeping the same extension on Linux
本文介绍了重命名多个文件,同时在Linux上保留相同的扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目录中有100个文件,使用以下命名约定.
I have 100s of files in a directory with the following naming convention.
00XYZCD042ABCDE20141002ABCDE.XML
00XYZCC011ABCDE20141002.TXT
00XYZCB165ABCDE20141002ABCDE.TXT
00XYZCB165ABCDE20141002ABCDE.CSV
我想使用 bash
, awk
, cut
, sed
重命名这些文件,以便获得输出:
I want to rename these files using bash
, awk
, cut
, sed
, so that I get the output:
XYZCD042.XML
XYZCC011.TXT
XYZCB165.TXT
XYZCB165.CSV
因此,基本上,始终删除前两个0,然后保留所有内容,直到ABCDE启动,然后删除所有内容,包括ABCDE并保留文件扩展名.
So basically, remove the first two 0s always, and then keep everything until ABCDE starts and then remove everything including ABCDE and keep the file extension.
推荐答案
仅限重击:
for fn in *; do
A=${fn#00}
mv $fn ${A/ABCDE*./.}
done
for循环中的第一行去除00前缀,第二行去除ABCDE后缀(最多一个点),然后执行重命名.
The first line in the for loop strips the 00 prefix, and the second line strips the ABCDE suffix (up to a dot), then performs the rename.
这篇关于重命名多个文件,同时在Linux上保留相同的扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文