Bash command to remove leading zeros from all file names

前端 未结 8 1823
一整个雨季
一整个雨季 2021-02-08 23:35

I have a directory with a bunch of files with names like:

001234.jpg
001235.jpg
004729342.jpg

I want to remove the leading zeros from all file

8条回答
  •  我在风中等你
    2021-02-09 00:37

    Here's one that doesn't require sed:

    for x in *.jpg ; do let num="10#${x%%.jpg}"; mv $x ${num}.jpg ;  done
    

    Note that this ONLY works when the filenames are all numbers. You could also remove the leading zeros using the shell:

    for a in *.jpg ; do dest=${a/*(0)/} ; mv $a $dest ; done
    

提交回复
热议问题