批量重命名文件 [英] Batch rename files
本文介绍了批量重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想批量重命名目录中的文件数。
I want to batch re-name a number of files in a directory so that the preceding number and hypen are stripped from the file name.
Old file name: 2904495-XXX_01_xxxx_20130730235001_00000000.NEW
New file name: XXX_01_xxxx_20130730235001_00000000.NEW
我怎么能做到这一点与Linux命令?
How can I do this with a linux command?
推荐答案
这应该使它:
rename 's/^[0-9]*-//;' *
$ -
它从一开始块 [0-9]
(即数字)很多次,那么连字符变C $ C>并从文件名称中删除。
It gets from the beginning the block [0-9]
(that is, numbers) many times, then the hyphen -
and deletes it from the file name.
如果改名
是不是在你的机器,你可以使用一个循环和 MV
:
If rename
is not in your machine, you can use a loop and mv
:
mv "$f" "${f#[0-9]*-}"
测试
$ ls
23-aa hello aaa23-aa
$ rename 's/^[0-9]*-//;' *
$ ls
aa hello aaa23-aa
或者
$ ls
23-a aa23-a hello
$ for f in *;
> do
> mv "$f" "${f#[0-9]*-}"
> done
$ ls
a aa23-a hello
这篇关于批量重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文