Linux shell script to add leading zeros to file names

后端 未结 10 1528
梦如初夏
梦如初夏 2020-12-04 06:43

I have a folder with about 1,700 files. They are all named like 1.txt or 1497.txt, etc. I would like to rename all the files so that all the filena

10条回答
  •  有刺的猬
    2020-12-04 07:28

    There is a rename.ul command installed from util-linux package (at least in Ubuntu) by default installed.

    It's use is (do a man rename.ul):

    rename [options] expression replacement file...

    The command will replace the first occurrence of expression with the given replacement for the provided files.

    While forming the command you can use:

    rename.ul -nv replace-me with-this in-all?-these-files*
    

    for not doing any changes but reading what changes that command would make. When sure just reexecute the command without the -v (verbose) and -n (no-act) options

    for your case the commands are:

    rename.ul "" 000 ?.txt
    rename.ul "" 00 ??.txt
    rename.ul "" 0 ???.txt
    

提交回复
热议问题