将目录中的所有文件从$ filename_h重命名为$ filename_half?
死简单。
我如何重命名
05_h.png 06_h.png 至
 05_half.png 06_half.png 
至less,我认为这很简单,但是除非你已经知道,否则Google很难去做这种事情。
谢谢….
只需使用bash,不需要调用外部命令。
 for file in *_h.png do mv "$file" "${file/_h.png/_half.png}" done 
  不要添加#!/bin/sh 
对那些需要单线的人来说:
 for file in *.png; do mv "$file" "${file/_h.png/_half.png}"; done 
 尝试rename命令: 
 rename 's/_h.png/_half.png/' *.png 
更新:
示例用法:
创build一些内容
 $ mkdir /tmp/foo $ cd /tmp/foo $ touch one_h.png two_h.png three_h.png $ ls one_h.png three_h.png two_h.png 
testingscheme:
 $ rename 's/_h.png/_half.png/' *.png $ ls one_half.png three_half.png two_half.png 
你在寻找纯粹的bash解决scheme吗? 有很多方法,但是这里有一个。
 for file in *_h.png ; do mv "$file" "${file%%_h.png}_half.png" ; done 
 这假定当前目录中以_h.png结尾的唯一文件是您要重命名的文件。 
更具体地说
 for file in 0{5..6}_h.png ; do mv "$file" "${file/_h./_half.}" 
假设这两个例子是你唯一的。 文件。
一般情况下,文件重命名已经 被 覆盖了 。
 for f in *.png; do fnew=`echo $f | sed 's/_h.png/_half.png/'` mv $f $fnew done 
 使用Perl编写的rename实用程序。 虽然可能是默认情况下不可用 
 $ touch 0{5..6}_h.png $ ls 05_h.png 06_h.png $ rename 's/h/half/' *.png $ ls 05_half.png 06_half.png 
 for i in *_h.png ; do mv $i `echo "$i"|awk -F'.' '{print $1"alf."$2}'` done 
另一种方法可以手动使用批量重命名选项
右键点击文件 – >文件自定义命令 – >批量重命名,你可以replaceh。 一半。
这将适用于基于Linux的GUI使用WinSCP等
 使用rename实用程序: 
 rc@bvm3:/tmp/foo $ touch 05_h.png 06_h.png rc@bvm3:/tmp/foo $ rename 's/_h/_half/' * rc@bvm3:/tmp/foo $ ls -l total 0 -rw-r--r-- 1 rc rc 0 2011-09-17 00:15 05_half.png -rw-r--r-- 1 rc rc 0 2011-09-17 00:15 06_half.png