Renaming a set of files to 001, 002, … on Linux

后端 未结 6 542
离开以前
离开以前 2020-12-05 07:51

I originally had a set of images of the form image_001.jpg, image_002.jpg, ...

I went through them and removed several. Now I\'d like to rename the leftover files ba

6条回答
  •  离开以前
    2020-12-05 08:25

    A simple loop (test with echo, execute with mv):

    I=1
    for F in *; do
      echo "$F" `printf image_%03d.jpg $I`
      #mv "$F" `printf image_%03d.jpg $I` 2>/dev/null || true
      I=$((I + 1))
    done
    

    (I added 2>/dev/null || true to suppress warnings about identical source and target files. If this is not to your liking, go with Matthew Flaschen's answer.)

提交回复
热议问题