2011-04-12 50 views
1

我在一个包含空格,撇号等的目录中有大约50个文件。我该如何进行批量重命名以删除撇号并用下划线替换空格?从终端大量替换文件名中的字符?

我可以做

ls | grep '*.txt' | xargs .... 

,但我不知道该怎么在xargs的做到位

+0

的可能重复【如何做大规模重新命名?](http://stackoverflow.com/questions/417916/how-to-do-a-mass-rename) – 2011-04-12 04:14:52

+0

你能后的文件名(S )? – 2011-04-12 04:20:56

回答

2

我用ren-regexp,这是一个Perl脚本,可以让你很容易批量重命名文件。

你会做一些像ren-regexp 's/ /_/g' *.txt

$ ls -l 
total 16 
-rw-r--r-- 1 marc marc 7 Apr 11 21:18 That's a wrap.txt 
-rw-r--r-- 1 marc marc 6 Apr 11 21:18 What's the time.txt 

$ ren-regexp "s/\'//g" "s/ /_/g" *.txt 

    That's a wrap.txt 
1 Thats a wrap.txt 
2 Thats_a_wrap.txt 

    What's the time.txt 
1 Whats the time.txt 
2 Whats_the_time.txt 


$ ls -l 
total 16 
-rw-r--r-- 1 marc marc 7 Apr 11 21:18 Thats_a_wrap.txt 
-rw-r--r-- 1 marc marc 6 Apr 11 21:18 Whats_the_time.txt