请教如何用命令来批量修改文件名?[已经解决]

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
aszxas
帖子: 75
注册时间: 2007-02-06 21:58

请教如何用命令来批量修改文件名?[已经解决]

#1

帖子 aszxas » 2007-02-11 20:25

例:
filename-1.txt.bak
filename-2.txt.bak
filename-3.txt.bak
filename-4.txt.bak

改为

filename-1.txt
filename-2.txt
filename-3.txt
filename-4.txt

用命令:
mv *.txt.bak *.txt
不行!

要如何写,谢谢。
上次由 aszxas 在 2007-02-12 11:18,总共编辑 1 次。
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#2

帖子 BigSnake.NET » 2007-02-11 20:39

x="1 2 3 4"
for xx in $x; do mv filename-$xx.txt.bak filename-$xx.txt ; done;
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
yohu
帖子: 955
注册时间: 2006-12-18 17:04
来自: 福建泉州

#3

帖子 yohu » 2007-02-11 21:10

要是linux下有total commander楼主的问题就简单了,好怀念tc……
拥有超级牛力的搜索引擎:
http://www.google.com/linux
http://www.google.com/
头像
Jimmy.Zhou
帖子: 475
注册时间: 2006-12-05 21:51
来自: Vienna, Austria

#4

帖子 Jimmy.Zhou » 2007-02-11 21:58

呵呵,大家可以多到linuxtoy去看看,那里有很多好东西的。
比如lz和ls的问题都有解决的:

Krusader-双面板文件管理器,跟tc很像的,虽然是kde的软件,不过gnome也没有问题了。
http://linuxtoy.org/archives/krusader.html

在 Nautilus 中执行批量重命名操作
http://linuxtoy.org/archives/batch-rena ... tilus.html
Jimmy.Zhou

Acer Extensa 5620G
T5250 + HD 2400 XT + 2G DDR2 +160G SATA + iwp 3945
Ubuntu Intrepid Ibex + Firefox 3
yohu
帖子: 955
注册时间: 2006-12-18 17:04
来自: 福建泉州

#5

帖子 yohu » 2007-02-11 22:21

ls说的我用过了,上次karron推荐给我用,用了一下,界面上来说的确跟tc非常相似,但一些操作上还是有差异的,比如lz说的批量重命名这个功能就没有。gnome下也有类似的软件,gnome-commander,也是界面神似,但功能差很多。
拥有超级牛力的搜索引擎:
http://www.google.com/linux
http://www.google.com/
头像
Jimmy.Zhou
帖子: 475
注册时间: 2006-12-05 21:51
来自: Vienna, Austria

#6

帖子 Jimmy.Zhou » 2007-02-11 22:31

恩,因为我没有用,所以也不太清楚。但是linuxtoy和krusader的主页上都说新的1.8.0beta是有批量重命名文件的功能的。
Jimmy.Zhou

Acer Extensa 5620G
T5250 + HD 2400 XT + 2G DDR2 +160G SATA + iwp 3945
Ubuntu Intrepid Ibex + Firefox 3
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

简单得死的事情。

#7

帖子 eexpress » 2007-02-11 22:52

RENAME(1) Perl Programmers Reference Guide RENAME(1)

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 exten‐
sion, you might say

rename ’s/\.bak$//’ *.bak

To translate uppercase names to lower, you’d use
● 鸣学
aszxas
帖子: 75
注册时间: 2007-02-06 21:58

Re: 简单得死的事情。

#8

帖子 aszxas » 2007-02-12 11:17

eexpress 写了:RENAME(1) Perl Programmers Reference Guide RENAME(1)

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 exten‐
sion, you might say

rename ’s/\.bak$//’ *.bak

To translate uppercase names to lower, you’d use
谢谢,rename 很好用!!!!
回复