linux能否批量重命名,linux批量重命名方法
經(jīng)常會遇到需要批量重命名文件的情況,用鼠標(biāo)太夸張了,簡單總結(jié)兩種比較簡單的方法:
問題:
存在大量html文件,需要重命名為htm文件
1.rename
通常重命名的命令是mv,Larry Wall寫的rename具有更強(qiáng)大的功能。能夠用perl的正則語法結(jié)構(gòu)進(jìn)行文件重命名。NAME
rename - renames multiple files
SYNOPSIS
rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]
DESCRIPTION
"rename" renames the filenames supplied according to the rule specified
as the first argument. The perlexpr argument is a Perl expression
which is expected to modify the $_ string in Perl for at least some of
the filenames specified. If a given filename is not modified by the
expression, it will not be renamed. If no filenames are given on the
command line, filenames will be read via standard input.
For example, to rename all files matching "*.bak" to strip the
extension, you might say
rename 's//.bak$//' *.bak
To translate uppercase names to lower, you'd use
rename 'y/A-Z/a-z/' *
上面是rename的man手冊,針對上面重命名html文件的問題,解決如下:
rename 's/.html$/.htm/' *.html
簡單來說就是重命名所有html文件(*.html),將文件名結(jié)尾處.html替換為.htm('s/.html$/.htm/'),其實更簡單的表達(dá)式可以為's/l$//'
2.printf
使用shell命令中的prinf打印出需要的文件名,然后在使用mv重命名
for i in *.html
do
newname="`printf "%s" ${i/html}`"htm
mv $i $newname
done
總結(jié)
以上是生活随笔為你收集整理的linux能否批量重命名,linux批量重命名方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DT时代,企业要有“经营安全、安全经营”
- 下一篇: 手机号码测凶吉附带手机号码归属地C#版