Rename files by incrementing a number within the filename












9















I have a directory which contains numbered image files, something like this:



01.png
02.png
03.png
03.svg
04.png
05.png
06.jpg
07.png
08.png
09.png
09.svg
10.png


Sometimes there may be multiple versions of a file in different formats (eg. a png and svg version of the 03 and 09 files above) but the numbers are otherwise consecutive. Typically there are 40-80 such files in each directory. The numbers correspond to the order these images appear in a manuscript (a Word document, but that's not important). There is no other way to determine the order of the images.



If I add a new image to the manuscript I need to place a copy of the image in this directory with the correct numbering. So if the new image is the fifth in the manuscript I need to rename the files in the directory to this in order to make room for it:



01.png
02.png
03.png
03.svg
04.png
06.png
07.jpg
08.png
09.png
10.png
10.svg
11.png


What is the most straightforward way from the command line, or from a script or macro to renumber all the files starting at a certain number? I have a standard Fedora Linux install using bash.










share|improve this question



























    9















    I have a directory which contains numbered image files, something like this:



    01.png
    02.png
    03.png
    03.svg
    04.png
    05.png
    06.jpg
    07.png
    08.png
    09.png
    09.svg
    10.png


    Sometimes there may be multiple versions of a file in different formats (eg. a png and svg version of the 03 and 09 files above) but the numbers are otherwise consecutive. Typically there are 40-80 such files in each directory. The numbers correspond to the order these images appear in a manuscript (a Word document, but that's not important). There is no other way to determine the order of the images.



    If I add a new image to the manuscript I need to place a copy of the image in this directory with the correct numbering. So if the new image is the fifth in the manuscript I need to rename the files in the directory to this in order to make room for it:



    01.png
    02.png
    03.png
    03.svg
    04.png
    06.png
    07.jpg
    08.png
    09.png
    10.png
    10.svg
    11.png


    What is the most straightforward way from the command line, or from a script or macro to renumber all the files starting at a certain number? I have a standard Fedora Linux install using bash.










    share|improve this question

























      9












      9








      9


      7






      I have a directory which contains numbered image files, something like this:



      01.png
      02.png
      03.png
      03.svg
      04.png
      05.png
      06.jpg
      07.png
      08.png
      09.png
      09.svg
      10.png


      Sometimes there may be multiple versions of a file in different formats (eg. a png and svg version of the 03 and 09 files above) but the numbers are otherwise consecutive. Typically there are 40-80 such files in each directory. The numbers correspond to the order these images appear in a manuscript (a Word document, but that's not important). There is no other way to determine the order of the images.



      If I add a new image to the manuscript I need to place a copy of the image in this directory with the correct numbering. So if the new image is the fifth in the manuscript I need to rename the files in the directory to this in order to make room for it:



      01.png
      02.png
      03.png
      03.svg
      04.png
      06.png
      07.jpg
      08.png
      09.png
      10.png
      10.svg
      11.png


      What is the most straightforward way from the command line, or from a script or macro to renumber all the files starting at a certain number? I have a standard Fedora Linux install using bash.










      share|improve this question














      I have a directory which contains numbered image files, something like this:



      01.png
      02.png
      03.png
      03.svg
      04.png
      05.png
      06.jpg
      07.png
      08.png
      09.png
      09.svg
      10.png


      Sometimes there may be multiple versions of a file in different formats (eg. a png and svg version of the 03 and 09 files above) but the numbers are otherwise consecutive. Typically there are 40-80 such files in each directory. The numbers correspond to the order these images appear in a manuscript (a Word document, but that's not important). There is no other way to determine the order of the images.



      If I add a new image to the manuscript I need to place a copy of the image in this directory with the correct numbering. So if the new image is the fifth in the manuscript I need to rename the files in the directory to this in order to make room for it:



      01.png
      02.png
      03.png
      03.svg
      04.png
      06.png
      07.jpg
      08.png
      09.png
      10.png
      10.svg
      11.png


      What is the most straightforward way from the command line, or from a script or macro to renumber all the files starting at a certain number? I have a standard Fedora Linux install using bash.







      linux bash rename






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 11 '12 at 14:04









      robertcrobertc

      148116




      148116






















          5 Answers
          5






          active

          oldest

          votes


















          7














          I think that it should do the work:



          #!/bin/bash

          NEWFILE=$1

          for file in `ls|sort -g -r`
          do
          filename=$(basename "$file")
          extension=${filename##*.}
          filename=${filename%.*}

          if [ $filename -ge $NEWFILE ]
          then
          mv "$file" "$(($filename + 1))".$extension
          fi
          done


          Script takes one parameter - number of you new image.



          PS. Put script in another directory than your images. In images directory there should be only images named in this way that you described.






          share|improve this answer
























          • This looks promising, I'll try it in a few hours when I'm back on my laptop.

            – robertc
            Jun 11 '12 at 16:33











          • This will only works if your filename is not prefixed by non-numerics chars

            – mems
            Nov 15 '16 at 18:35











          • @mems The OP clearly states that filenames begin with a number

            – xhienne
            Jan 8 '17 at 13:16



















          2














          This would be easier in zsh, where you can use




          • the On glob qualifier to sort matches in decreasing order (and n to use numerical order, in case the file names don't all have leading zeroes to the same width);

          • the (l:WIDTH::FILLER:) parameter expansion flag to pad all numbers to the same width (the width of the larger number).


          break=$1   # the position at which you want to insert a file
          setopt extended_glob
          width=
          for x in [0-9]*(nOn); do
          n=${x%%[^0-9]*}
          if ((n < break)); then break; fi
          ((++n))
          [[ -n $width ]] || width=${#n}
          mv $x ${(l:$width::0:)n}${x##${x%%[^0-9]*}}
          done


          In bash, here's a script that assumes files are padded to a fixed width (otherwise, the script won't rename the right files) and pads to a fixed width (which must be specified).



          break=$1      # the position at which you want to insert a file
          width=9999 # the number of digits to pad numbers to
          files=([0-9]*)
          for ((i=#((${#files}-1)); i>=0; --i)); do
          n=${x%%[^0-9]*}
          x=${files[$i]}
          if ((n < break)); then continue; fi
          n=$((n + 1 + width + 1)); n=${n#1}
          mv -- "${files[$i]}" "$n${x##${x%%[^0-9]*}}"
          done





          share|improve this answer































            1














            This exact issue is covered in this article. Note that you would have to modify it to support the SVG and PNG formats, by adding a second MV step.






            share|improve this answer
























            • I don't think it is the exact issue, that's going renumber all the images every time. I just want to renumber the images from a particular point.

              – robertc
              Jun 11 '12 at 16:30



















            0














            Easier:



            touch file`ls file* | wc -l`.ext


            You'll get:



            $ ls file*
            file0.ext file1.ext file2.ext file3.ext file4.ext file5.ext file6.ext





            share|improve this answer
























            • How would I add the leading zero for 1-9? Also remember there may be two files 03.png and 03.svg.

              – robertc
              Apr 5 '18 at 11:39





















            0














            There doesn't seem to be much recent interest in this question but, should someone stumble upon it, there are three issues here. One is how to select files to rename based on semantic criteria (range is not lexical and cannot be specified by wildcards or even regular expressions-- automata theory says that this is more complex than an NFA). The second is how to change a name by modifying a portion of it. The third is how to avoid name collision. A script in Bash and many other languages can do this specific transform but most of us would rather not have to write a program every time we want to rename a bunch of files. With my (free and open source) rene.py you can do what you want but it takes two invocations to avoid the name collision problem. First rene ?.*/#7-80 %?.* B increments all names in the range, adding a prefix of % to avoid existing names. Then rene %* * removes this prefix from those files that have it. I describe this at https://sourceforge.net/p/rene-file-renamer/discussion/examples/thread/f0fe8aa63c/





            share























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f40523%2frename-files-by-incrementing-a-number-within-the-filename%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              5 Answers
              5






              active

              oldest

              votes








              5 Answers
              5






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              7














              I think that it should do the work:



              #!/bin/bash

              NEWFILE=$1

              for file in `ls|sort -g -r`
              do
              filename=$(basename "$file")
              extension=${filename##*.}
              filename=${filename%.*}

              if [ $filename -ge $NEWFILE ]
              then
              mv "$file" "$(($filename + 1))".$extension
              fi
              done


              Script takes one parameter - number of you new image.



              PS. Put script in another directory than your images. In images directory there should be only images named in this way that you described.






              share|improve this answer
























              • This looks promising, I'll try it in a few hours when I'm back on my laptop.

                – robertc
                Jun 11 '12 at 16:33











              • This will only works if your filename is not prefixed by non-numerics chars

                – mems
                Nov 15 '16 at 18:35











              • @mems The OP clearly states that filenames begin with a number

                – xhienne
                Jan 8 '17 at 13:16
















              7














              I think that it should do the work:



              #!/bin/bash

              NEWFILE=$1

              for file in `ls|sort -g -r`
              do
              filename=$(basename "$file")
              extension=${filename##*.}
              filename=${filename%.*}

              if [ $filename -ge $NEWFILE ]
              then
              mv "$file" "$(($filename + 1))".$extension
              fi
              done


              Script takes one parameter - number of you new image.



              PS. Put script in another directory than your images. In images directory there should be only images named in this way that you described.






              share|improve this answer
























              • This looks promising, I'll try it in a few hours when I'm back on my laptop.

                – robertc
                Jun 11 '12 at 16:33











              • This will only works if your filename is not prefixed by non-numerics chars

                – mems
                Nov 15 '16 at 18:35











              • @mems The OP clearly states that filenames begin with a number

                – xhienne
                Jan 8 '17 at 13:16














              7












              7








              7







              I think that it should do the work:



              #!/bin/bash

              NEWFILE=$1

              for file in `ls|sort -g -r`
              do
              filename=$(basename "$file")
              extension=${filename##*.}
              filename=${filename%.*}

              if [ $filename -ge $NEWFILE ]
              then
              mv "$file" "$(($filename + 1))".$extension
              fi
              done


              Script takes one parameter - number of you new image.



              PS. Put script in another directory than your images. In images directory there should be only images named in this way that you described.






              share|improve this answer













              I think that it should do the work:



              #!/bin/bash

              NEWFILE=$1

              for file in `ls|sort -g -r`
              do
              filename=$(basename "$file")
              extension=${filename##*.}
              filename=${filename%.*}

              if [ $filename -ge $NEWFILE ]
              then
              mv "$file" "$(($filename + 1))".$extension
              fi
              done


              Script takes one parameter - number of you new image.



              PS. Put script in another directory than your images. In images directory there should be only images named in this way that you described.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 11 '12 at 14:59









              pbmpbm

              17.2k52847




              17.2k52847













              • This looks promising, I'll try it in a few hours when I'm back on my laptop.

                – robertc
                Jun 11 '12 at 16:33











              • This will only works if your filename is not prefixed by non-numerics chars

                – mems
                Nov 15 '16 at 18:35











              • @mems The OP clearly states that filenames begin with a number

                – xhienne
                Jan 8 '17 at 13:16



















              • This looks promising, I'll try it in a few hours when I'm back on my laptop.

                – robertc
                Jun 11 '12 at 16:33











              • This will only works if your filename is not prefixed by non-numerics chars

                – mems
                Nov 15 '16 at 18:35











              • @mems The OP clearly states that filenames begin with a number

                – xhienne
                Jan 8 '17 at 13:16

















              This looks promising, I'll try it in a few hours when I'm back on my laptop.

              – robertc
              Jun 11 '12 at 16:33





              This looks promising, I'll try it in a few hours when I'm back on my laptop.

              – robertc
              Jun 11 '12 at 16:33













              This will only works if your filename is not prefixed by non-numerics chars

              – mems
              Nov 15 '16 at 18:35





              This will only works if your filename is not prefixed by non-numerics chars

              – mems
              Nov 15 '16 at 18:35













              @mems The OP clearly states that filenames begin with a number

              – xhienne
              Jan 8 '17 at 13:16





              @mems The OP clearly states that filenames begin with a number

              – xhienne
              Jan 8 '17 at 13:16













              2














              This would be easier in zsh, where you can use




              • the On glob qualifier to sort matches in decreasing order (and n to use numerical order, in case the file names don't all have leading zeroes to the same width);

              • the (l:WIDTH::FILLER:) parameter expansion flag to pad all numbers to the same width (the width of the larger number).


              break=$1   # the position at which you want to insert a file
              setopt extended_glob
              width=
              for x in [0-9]*(nOn); do
              n=${x%%[^0-9]*}
              if ((n < break)); then break; fi
              ((++n))
              [[ -n $width ]] || width=${#n}
              mv $x ${(l:$width::0:)n}${x##${x%%[^0-9]*}}
              done


              In bash, here's a script that assumes files are padded to a fixed width (otherwise, the script won't rename the right files) and pads to a fixed width (which must be specified).



              break=$1      # the position at which you want to insert a file
              width=9999 # the number of digits to pad numbers to
              files=([0-9]*)
              for ((i=#((${#files}-1)); i>=0; --i)); do
              n=${x%%[^0-9]*}
              x=${files[$i]}
              if ((n < break)); then continue; fi
              n=$((n + 1 + width + 1)); n=${n#1}
              mv -- "${files[$i]}" "$n${x##${x%%[^0-9]*}}"
              done





              share|improve this answer




























                2














                This would be easier in zsh, where you can use




                • the On glob qualifier to sort matches in decreasing order (and n to use numerical order, in case the file names don't all have leading zeroes to the same width);

                • the (l:WIDTH::FILLER:) parameter expansion flag to pad all numbers to the same width (the width of the larger number).


                break=$1   # the position at which you want to insert a file
                setopt extended_glob
                width=
                for x in [0-9]*(nOn); do
                n=${x%%[^0-9]*}
                if ((n < break)); then break; fi
                ((++n))
                [[ -n $width ]] || width=${#n}
                mv $x ${(l:$width::0:)n}${x##${x%%[^0-9]*}}
                done


                In bash, here's a script that assumes files are padded to a fixed width (otherwise, the script won't rename the right files) and pads to a fixed width (which must be specified).



                break=$1      # the position at which you want to insert a file
                width=9999 # the number of digits to pad numbers to
                files=([0-9]*)
                for ((i=#((${#files}-1)); i>=0; --i)); do
                n=${x%%[^0-9]*}
                x=${files[$i]}
                if ((n < break)); then continue; fi
                n=$((n + 1 + width + 1)); n=${n#1}
                mv -- "${files[$i]}" "$n${x##${x%%[^0-9]*}}"
                done





                share|improve this answer


























                  2












                  2








                  2







                  This would be easier in zsh, where you can use




                  • the On glob qualifier to sort matches in decreasing order (and n to use numerical order, in case the file names don't all have leading zeroes to the same width);

                  • the (l:WIDTH::FILLER:) parameter expansion flag to pad all numbers to the same width (the width of the larger number).


                  break=$1   # the position at which you want to insert a file
                  setopt extended_glob
                  width=
                  for x in [0-9]*(nOn); do
                  n=${x%%[^0-9]*}
                  if ((n < break)); then break; fi
                  ((++n))
                  [[ -n $width ]] || width=${#n}
                  mv $x ${(l:$width::0:)n}${x##${x%%[^0-9]*}}
                  done


                  In bash, here's a script that assumes files are padded to a fixed width (otherwise, the script won't rename the right files) and pads to a fixed width (which must be specified).



                  break=$1      # the position at which you want to insert a file
                  width=9999 # the number of digits to pad numbers to
                  files=([0-9]*)
                  for ((i=#((${#files}-1)); i>=0; --i)); do
                  n=${x%%[^0-9]*}
                  x=${files[$i]}
                  if ((n < break)); then continue; fi
                  n=$((n + 1 + width + 1)); n=${n#1}
                  mv -- "${files[$i]}" "$n${x##${x%%[^0-9]*}}"
                  done





                  share|improve this answer













                  This would be easier in zsh, where you can use




                  • the On glob qualifier to sort matches in decreasing order (and n to use numerical order, in case the file names don't all have leading zeroes to the same width);

                  • the (l:WIDTH::FILLER:) parameter expansion flag to pad all numbers to the same width (the width of the larger number).


                  break=$1   # the position at which you want to insert a file
                  setopt extended_glob
                  width=
                  for x in [0-9]*(nOn); do
                  n=${x%%[^0-9]*}
                  if ((n < break)); then break; fi
                  ((++n))
                  [[ -n $width ]] || width=${#n}
                  mv $x ${(l:$width::0:)n}${x##${x%%[^0-9]*}}
                  done


                  In bash, here's a script that assumes files are padded to a fixed width (otherwise, the script won't rename the right files) and pads to a fixed width (which must be specified).



                  break=$1      # the position at which you want to insert a file
                  width=9999 # the number of digits to pad numbers to
                  files=([0-9]*)
                  for ((i=#((${#files}-1)); i>=0; --i)); do
                  n=${x%%[^0-9]*}
                  x=${files[$i]}
                  if ((n < break)); then continue; fi
                  n=$((n + 1 + width + 1)); n=${n#1}
                  mv -- "${files[$i]}" "$n${x##${x%%[^0-9]*}}"
                  done






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jun 12 '12 at 1:39









                  GillesGilles

                  539k12810911606




                  539k12810911606























                      1














                      This exact issue is covered in this article. Note that you would have to modify it to support the SVG and PNG formats, by adding a second MV step.






                      share|improve this answer
























                      • I don't think it is the exact issue, that's going renumber all the images every time. I just want to renumber the images from a particular point.

                        – robertc
                        Jun 11 '12 at 16:30
















                      1














                      This exact issue is covered in this article. Note that you would have to modify it to support the SVG and PNG formats, by adding a second MV step.






                      share|improve this answer
























                      • I don't think it is the exact issue, that's going renumber all the images every time. I just want to renumber the images from a particular point.

                        – robertc
                        Jun 11 '12 at 16:30














                      1












                      1








                      1







                      This exact issue is covered in this article. Note that you would have to modify it to support the SVG and PNG formats, by adding a second MV step.






                      share|improve this answer













                      This exact issue is covered in this article. Note that you would have to modify it to support the SVG and PNG formats, by adding a second MV step.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 11 '12 at 14:39









                      Jodie CJodie C

                      1,6271013




                      1,6271013













                      • I don't think it is the exact issue, that's going renumber all the images every time. I just want to renumber the images from a particular point.

                        – robertc
                        Jun 11 '12 at 16:30



















                      • I don't think it is the exact issue, that's going renumber all the images every time. I just want to renumber the images from a particular point.

                        – robertc
                        Jun 11 '12 at 16:30

















                      I don't think it is the exact issue, that's going renumber all the images every time. I just want to renumber the images from a particular point.

                      – robertc
                      Jun 11 '12 at 16:30





                      I don't think it is the exact issue, that's going renumber all the images every time. I just want to renumber the images from a particular point.

                      – robertc
                      Jun 11 '12 at 16:30











                      0














                      Easier:



                      touch file`ls file* | wc -l`.ext


                      You'll get:



                      $ ls file*
                      file0.ext file1.ext file2.ext file3.ext file4.ext file5.ext file6.ext





                      share|improve this answer
























                      • How would I add the leading zero for 1-9? Also remember there may be two files 03.png and 03.svg.

                        – robertc
                        Apr 5 '18 at 11:39


















                      0














                      Easier:



                      touch file`ls file* | wc -l`.ext


                      You'll get:



                      $ ls file*
                      file0.ext file1.ext file2.ext file3.ext file4.ext file5.ext file6.ext





                      share|improve this answer
























                      • How would I add the leading zero for 1-9? Also remember there may be two files 03.png and 03.svg.

                        – robertc
                        Apr 5 '18 at 11:39
















                      0












                      0








                      0







                      Easier:



                      touch file`ls file* | wc -l`.ext


                      You'll get:



                      $ ls file*
                      file0.ext file1.ext file2.ext file3.ext file4.ext file5.ext file6.ext





                      share|improve this answer













                      Easier:



                      touch file`ls file* | wc -l`.ext


                      You'll get:



                      $ ls file*
                      file0.ext file1.ext file2.ext file3.ext file4.ext file5.ext file6.ext






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 5 '18 at 11:35









                      Hugoren MartinakoHugoren Martinako

                      184




                      184













                      • How would I add the leading zero for 1-9? Also remember there may be two files 03.png and 03.svg.

                        – robertc
                        Apr 5 '18 at 11:39





















                      • How would I add the leading zero for 1-9? Also remember there may be two files 03.png and 03.svg.

                        – robertc
                        Apr 5 '18 at 11:39



















                      How would I add the leading zero for 1-9? Also remember there may be two files 03.png and 03.svg.

                      – robertc
                      Apr 5 '18 at 11:39







                      How would I add the leading zero for 1-9? Also remember there may be two files 03.png and 03.svg.

                      – robertc
                      Apr 5 '18 at 11:39













                      0














                      There doesn't seem to be much recent interest in this question but, should someone stumble upon it, there are three issues here. One is how to select files to rename based on semantic criteria (range is not lexical and cannot be specified by wildcards or even regular expressions-- automata theory says that this is more complex than an NFA). The second is how to change a name by modifying a portion of it. The third is how to avoid name collision. A script in Bash and many other languages can do this specific transform but most of us would rather not have to write a program every time we want to rename a bunch of files. With my (free and open source) rene.py you can do what you want but it takes two invocations to avoid the name collision problem. First rene ?.*/#7-80 %?.* B increments all names in the range, adding a prefix of % to avoid existing names. Then rene %* * removes this prefix from those files that have it. I describe this at https://sourceforge.net/p/rene-file-renamer/discussion/examples/thread/f0fe8aa63c/





                      share




























                        0














                        There doesn't seem to be much recent interest in this question but, should someone stumble upon it, there are three issues here. One is how to select files to rename based on semantic criteria (range is not lexical and cannot be specified by wildcards or even regular expressions-- automata theory says that this is more complex than an NFA). The second is how to change a name by modifying a portion of it. The third is how to avoid name collision. A script in Bash and many other languages can do this specific transform but most of us would rather not have to write a program every time we want to rename a bunch of files. With my (free and open source) rene.py you can do what you want but it takes two invocations to avoid the name collision problem. First rene ?.*/#7-80 %?.* B increments all names in the range, adding a prefix of % to avoid existing names. Then rene %* * removes this prefix from those files that have it. I describe this at https://sourceforge.net/p/rene-file-renamer/discussion/examples/thread/f0fe8aa63c/





                        share


























                          0












                          0








                          0







                          There doesn't seem to be much recent interest in this question but, should someone stumble upon it, there are three issues here. One is how to select files to rename based on semantic criteria (range is not lexical and cannot be specified by wildcards or even regular expressions-- automata theory says that this is more complex than an NFA). The second is how to change a name by modifying a portion of it. The third is how to avoid name collision. A script in Bash and many other languages can do this specific transform but most of us would rather not have to write a program every time we want to rename a bunch of files. With my (free and open source) rene.py you can do what you want but it takes two invocations to avoid the name collision problem. First rene ?.*/#7-80 %?.* B increments all names in the range, adding a prefix of % to avoid existing names. Then rene %* * removes this prefix from those files that have it. I describe this at https://sourceforge.net/p/rene-file-renamer/discussion/examples/thread/f0fe8aa63c/





                          share













                          There doesn't seem to be much recent interest in this question but, should someone stumble upon it, there are three issues here. One is how to select files to rename based on semantic criteria (range is not lexical and cannot be specified by wildcards or even regular expressions-- automata theory says that this is more complex than an NFA). The second is how to change a name by modifying a portion of it. The third is how to avoid name collision. A script in Bash and many other languages can do this specific transform but most of us would rather not have to write a program every time we want to rename a bunch of files. With my (free and open source) rene.py you can do what you want but it takes two invocations to avoid the name collision problem. First rene ?.*/#7-80 %?.* B increments all names in the range, adding a prefix of % to avoid existing names. Then rene %* * removes this prefix from those files that have it. I describe this at https://sourceforge.net/p/rene-file-renamer/discussion/examples/thread/f0fe8aa63c/






                          share











                          share


                          share










                          answered 5 mins ago









                          David McCrackenDavid McCracken

                          1




                          1






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f40523%2frename-files-by-incrementing-a-number-within-the-filename%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              CARDNET

                              Boot-repair Failure: Unable to locate package grub-common:i386

                              濃尾地震