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

前端 未结 11 890
执念已碎
执念已碎 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:36

    Another approach can be manually using batch rename option

    Right click on the file -> File Custom Commands -> Batch Rename and you can replace h. with half.

    This will work for linux based gui using WinSCP etc

    0 讨论(0)
  • 2020-12-02 04:36

    One liner:
    for file in *.php ; do mv "$file" "_$file" ; done

    0 讨论(0)
  • 2020-12-02 04:41

    I had a similar question: In the manual, it describes rename as

    rename [option] expression replacement file
    

    so you can use it in this way

    rename _h _half *.png
    

    In the code: '_h' is the expression that you are looking for. '_half' is the pattern that you want to replace with. '*.png' is the range of files that you are looking for your possible target files.

    Hope this can help c:

    0 讨论(0)
  • 2020-12-02 04:41

    Although the answer set is complete, I need to add another missing one.

    for i in *_h.png;
      do name=`echo "$i" | cut -d'_' -f1`
      echo "Executing of name $name" 
      mv "$i" "${name}_half.png"
    done
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题