Rename all files in directory from $filename_h to $filename_half?

前端 未结 11 899
执念已碎
执念已碎 2020-12-02 03:45

Dead simple.

How do I rename

05_h.png
06_h.png

to

05_half.png
06_half.png

At least, I think it\

11条回答
  •  旧巷少年郎
    2020-12-02 04:43

    Just use bash, no need to call external commands.

    for file in *_h.png
    do
      mv "$file" "${file/_h.png/_half.png}"
    done
    

    Do not add #!/bin/sh

    For those that need that one-liner:

    for file in *.png; do mv "$file" "${file/_h.png/_half.png}"; done
    

提交回复
热议问题