How to use sed to change file extensions?

前端 未结 6 790
粉色の甜心
粉色の甜心 2021-01-01 06:33

I have to do a sed line (also using pipes in Linux) to change a file extension, so I can do some kind of mv *.1stextension *.2ndextension like mv *.txt *.

6条回答
  •  灰色年华
    2021-01-01 07:08

    You may try following options

    Option 1 find along with rename

    find . -type f -name "*.ext1" -exec rename -f 's/\.ext1$/ext2/' {} \;
    

    Option 2 find along with mv

    find . -type f -name "*.ext1" -exec sh -c 'mv -f $0 ${0%.ext1}.ext2' {} \;
    

    Note: It is observed that rename doesn't work for many terminals

提交回复
热议问题