I rename few files (1234.xml
, 9876.xml
, 2345.xml
etc) with .xml
extension with the following code :
for i in *.xml
do
mv $i $i.ab
done
it becomes 1234.xml.ab
, 9876.xml.ab
, 2345.xml.ab
...etc
Now, I want to rename it to 1234.x开发者_开发问答ml.SD
, 9876.xml.SD
, 2345.xml.SD
...etc.
These are 100 files.
How can this be achieved with the help of code ? Please advise.
If you are using bash you can do:
for f in *.xml.ab; do
mv "$f" "${f%.ab}.SD"
done
or just use the rename
command as:
rename 's/ab$/SD/' *.xml.ab
You can do it like that:
for f in *.xml.ab; do
mv $f `echo $f | sed 's/\.ab$//g'`
done
I'm not clear if you want to rename foo.xml.ab -> foo.xml or foo.xml.ab -> foo.xml.SD
foo.xml.ab -> foo.xml
for f in *.xml.ab; do
mv "$f" "${f%.ab}"
done
foo.xml.ab -> foo.xml.SD
for f in *.xml.ab; do
mv "$f" "${f/.ab/.SD}"
done
精彩评论