How to rename with prefix/suffix?

前端 未结 9 1506
独厮守ぢ
独厮守ぢ 2020-11-27 10:52

How do I do mv original.filename new.original.filename without retyping the original filename?

I would imagine being able to do something like mv

9条回答
  •  独厮守ぢ
    2020-11-27 11:29

    You could use the rename(1) command:

    rename 's/(.*)$/new.$1/' original.filename
    

    Edit: If rename isn't available and you have to rename more than one file, shell scripting can really be short and simple for this. For example, to rename all *.jpg to prefix_*.jpg in the current directory:

    for filename in *.jpg; do mv "$filename" "prefix_$filename"; done;
    

提交回复
热议问题