当前位置: 技术问答>linux和unix
如何用shell改变一个目录下的指定文件后缀名.如:从*.TXT改变成*.txt(包括子目录)
来源: 互联网 发布时间:2015-09-11
本文导语: 力求shell最简单 | #! /bin/sh find /tmp/tt -type f | grep ".TXT" | nawk '{ OldName=$1; NewName=gsub(/.TXT/, ".txt"); print "mv "OldName" "$NewName }' | /bin/sh | find ./...
力求shell最简单
|
#! /bin/sh
find /tmp/tt -type f | grep ".TXT" | nawk '{
OldName=$1;
NewName=gsub(/.TXT/, ".txt");
print "mv "OldName" "$NewName
}' | /bin/sh
find /tmp/tt -type f | grep ".TXT" | nawk '{
OldName=$1;
NewName=gsub(/.TXT/, ".txt");
print "mv "OldName" "$NewName
}' | /bin/sh
|
find ./ -name "*.TXT" -exec echo "mv {} {}" ';' | sed -e 's/.TXT/.txt/' | sed -e 's/.TXT/.txt/' | sed -e 's/.txt/.TXT/' | sh
|
#!/bin/bash
if [ $# -ne 2 ];then
echo "usage: change ori new"
exit
else
ori=$1
new=$2
fi
for fname in `ls -1 | grep ${ori}$`
do
mv $fname ${fname//$ori/$new}
done
通用点的~
if [ $# -ne 2 ];then
echo "usage: change ori new"
exit
else
ori=$1
new=$2
fi
for fname in `ls -1 | grep ${ori}$`
do
mv $fname ${fname//$ori/$new}
done
通用点的~