batch rename files with ids intact

后端 未结 2 1287
独厮守ぢ
独厮守ぢ 2021-01-23 17:50

i have a directory listing like

seascaperecovered0088crop.jpg 
seascaperecovered0096crop.jpg
seascaperecovered0098crop.jpg
seascaperecovered0101crop.jpg
seascape         


        
相关标签:
2条回答
  • 2021-01-23 18:12

    With bash regular expressions

    for file in *; do 
      [[ "$file" =~ [0-9]+ ]] && mv "$file" seascape_${BASH_REMATCH[0]}.jpg 
    done
    
    0 讨论(0)
  • 2021-01-23 18:16

    Very straightforward:

    for i in seascaperecovered*.jpg; do A=${i/crop/}; mv $i ${A/recovered/_}; done
    

    (Put echo before the mv first for a dry run.)

    0 讨论(0)
提交回复
热议问题