Google

如何批量修改文件名

2007-11-29 22:56 来源: zhanyoun.cublog.cn 作者:zhanyoun 网友评论 0 条 浏览次数 232
方法很多,这里[转]贴出来两个,主要是体会一下sed and awk 的用法。
 
 
 
 

现在有多个文件,a.txt,b.txt,c.txt....现在想用个shell程序实现批量改文件名为a,b,c去掉后面的.txt


find ./ -name "*.txt" -exec echo "mv {} {}" ';' | sed -e 's/.txt/.TXT/' | sed -e 's/.txt//' | sed -e 's/.TXT/.txt/' | sh


#! /bin/sh
find /tmp -type f | grep ".txt" | nawk '{
OldName=$1;
NewName=gsub(/.txt/, "");
print "mv "OldName" "$NewName
}' | /bin/sh

 

 

上一篇: 下一篇:

相关主题:find  awk  sed  批量修改文件名

网友评论