参见英文答案 >
Rename filename to another name3个
假设我有一堆文件名为:bsdsa120226.nai bdeqa140223.nai,我想将它们重命名为120226.nai 140223.nai.我怎样才能使用下面的脚本实现这一目标?
原文链接:https://www.f2er.com/bash/385214.html假设我有一堆文件名为:bsdsa120226.nai bdeqa140223.nai,我想将它们重命名为120226.nai 140223.nai.我怎样才能使用下面的脚本实现这一目标?
#!/bin/bash name1=`ls *nai*` names=`ls *nai*| grep -Po '(?<=.{5}).+'` for i in $name1 do for y in $names do mv $i $y done done Solution: name1=`ls *nai*` for i in $name1 do y=$(echo "$i" | grep -Po '(?<=.{5}).+') mv $i $y done