Renaming multiple files with Bash [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite













This question already has an answer here:



  • How to rename multiple files sequentially from command line?

    6 answers



I have a lot of files to process and I need to replace their original names with this format in bash:



00000000000001_1.jpg 
00000000000002_1.jpg
00000000000003_1.jpg


and so on










share|improve this question















marked as duplicate by WinEunuuchs2Unix, waltinator, Byte Commander, Sergiy Kolodyazhnyy bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 19 at 23:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















    up vote
    1
    down vote

    favorite













    This question already has an answer here:



    • How to rename multiple files sequentially from command line?

      6 answers



    I have a lot of files to process and I need to replace their original names with this format in bash:



    00000000000001_1.jpg 
    00000000000002_1.jpg
    00000000000003_1.jpg


    and so on










    share|improve this question















    marked as duplicate by WinEunuuchs2Unix, waltinator, Byte Commander, Sergiy Kolodyazhnyy bash
    Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Mar 19 at 23:15


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite












      This question already has an answer here:



      • How to rename multiple files sequentially from command line?

        6 answers



      I have a lot of files to process and I need to replace their original names with this format in bash:



      00000000000001_1.jpg 
      00000000000002_1.jpg
      00000000000003_1.jpg


      and so on










      share|improve this question
















      This question already has an answer here:



      • How to rename multiple files sequentially from command line?

        6 answers



      I have a lot of files to process and I need to replace their original names with this format in bash:



      00000000000001_1.jpg 
      00000000000002_1.jpg
      00000000000003_1.jpg


      and so on





      This question already has an answer here:



      • How to rename multiple files sequentially from command line?

        6 answers







      bash batch-rename






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 19 at 21:40









      Zanna

      48.1k13119228




      48.1k13119228










      asked Mar 19 at 21:32









      deXterlab97

      286




      286




      marked as duplicate by WinEunuuchs2Unix, waltinator, Byte Commander, Sergiy Kolodyazhnyy bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 19 at 23:15


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by WinEunuuchs2Unix, waltinator, Byte Commander, Sergiy Kolodyazhnyy bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 19 at 23:15


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Adapted from one of Oli's answers:



          rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *


          This takes every file in the current directory and renames it with a number with 14 digits (I hope I counted correctly) followed by _1.jpg. our $i introduces a global variable i, which is then increased by one and printed with sprintf. e commands rename to evaluate the right side of the replacement (= everything between the second and the third /) as an expression rather than literally. If you're happy with the results, remove -n to perform the renaming.



          If you want to dive into perl expressions and their beauty, the perldoc is the way to go.






          share|improve this answer






















          • This is a good approach. The Perl rename utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
            – Eliah Kagan
            Mar 20 at 5:43


















          up vote
          2
          down vote













          Would this works for you :



          i=1
          for file in *; do
          mv "$file" "$(printf %014d $i)_1.jpg"
          i=$((i+1))
          done


          It will rename every file in the current directory like this :



          00000000000001_1.jpg
          .
          .
          00000000000009_1.jpg
          .
          .
          00000000000010_1.jpg
          .
          .





          share|improve this answer






















          • replace ._$file with _1.jpg and I think you've got it.
            – WinEunuuchs2Unix
            Mar 19 at 23:10










          • I edited my answer, I thought _1.jpg was supposed to be the original file name.
            – Paul
            Mar 19 at 23:57










          • Looking better. Just need to change ._1.jpg to _1.jpg then I think it's perfect.
            – WinEunuuchs2Unix
            Mar 20 at 1:48

















          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          Adapted from one of Oli's answers:



          rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *


          This takes every file in the current directory and renames it with a number with 14 digits (I hope I counted correctly) followed by _1.jpg. our $i introduces a global variable i, which is then increased by one and printed with sprintf. e commands rename to evaluate the right side of the replacement (= everything between the second and the third /) as an expression rather than literally. If you're happy with the results, remove -n to perform the renaming.



          If you want to dive into perl expressions and their beauty, the perldoc is the way to go.






          share|improve this answer






















          • This is a good approach. The Perl rename utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
            – Eliah Kagan
            Mar 20 at 5:43















          up vote
          4
          down vote



          accepted










          Adapted from one of Oli's answers:



          rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *


          This takes every file in the current directory and renames it with a number with 14 digits (I hope I counted correctly) followed by _1.jpg. our $i introduces a global variable i, which is then increased by one and printed with sprintf. e commands rename to evaluate the right side of the replacement (= everything between the second and the third /) as an expression rather than literally. If you're happy with the results, remove -n to perform the renaming.



          If you want to dive into perl expressions and their beauty, the perldoc is the way to go.






          share|improve this answer






















          • This is a good approach. The Perl rename utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
            – Eliah Kagan
            Mar 20 at 5:43













          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          Adapted from one of Oli's answers:



          rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *


          This takes every file in the current directory and renames it with a number with 14 digits (I hope I counted correctly) followed by _1.jpg. our $i introduces a global variable i, which is then increased by one and printed with sprintf. e commands rename to evaluate the right side of the replacement (= everything between the second and the third /) as an expression rather than literally. If you're happy with the results, remove -n to perform the renaming.



          If you want to dive into perl expressions and their beauty, the perldoc is the way to go.






          share|improve this answer














          Adapted from one of Oli's answers:



          rename -n 's/.+/our $i; $i++; sprintf("%014d_1.jpg", $i)/e' *


          This takes every file in the current directory and renames it with a number with 14 digits (I hope I counted correctly) followed by _1.jpg. our $i introduces a global variable i, which is then increased by one and printed with sprintf. e commands rename to evaluate the right side of the replacement (= everything between the second and the third /) as an expression rather than literally. If you're happy with the results, remove -n to perform the renaming.



          If you want to dive into perl expressions and their beauty, the perldoc is the way to go.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 19 at 23:20

























          answered Mar 19 at 23:13









          dessert

          19.8k55694




          19.8k55694











          • This is a good approach. The Perl rename utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
            – Eliah Kagan
            Mar 20 at 5:43

















          • This is a good approach. The Perl rename utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
            – Eliah Kagan
            Mar 20 at 5:43
















          This is a good approach. The Perl rename utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
          – Eliah Kagan
          Mar 20 at 5:43





          This is a good approach. The Perl rename utility is powerful, flexible, and fast. Note that the approach you've shown here can be simplified (but it does work just fine, as written).
          – Eliah Kagan
          Mar 20 at 5:43













          up vote
          2
          down vote













          Would this works for you :



          i=1
          for file in *; do
          mv "$file" "$(printf %014d $i)_1.jpg"
          i=$((i+1))
          done


          It will rename every file in the current directory like this :



          00000000000001_1.jpg
          .
          .
          00000000000009_1.jpg
          .
          .
          00000000000010_1.jpg
          .
          .





          share|improve this answer






















          • replace ._$file with _1.jpg and I think you've got it.
            – WinEunuuchs2Unix
            Mar 19 at 23:10










          • I edited my answer, I thought _1.jpg was supposed to be the original file name.
            – Paul
            Mar 19 at 23:57










          • Looking better. Just need to change ._1.jpg to _1.jpg then I think it's perfect.
            – WinEunuuchs2Unix
            Mar 20 at 1:48














          up vote
          2
          down vote













          Would this works for you :



          i=1
          for file in *; do
          mv "$file" "$(printf %014d $i)_1.jpg"
          i=$((i+1))
          done


          It will rename every file in the current directory like this :



          00000000000001_1.jpg
          .
          .
          00000000000009_1.jpg
          .
          .
          00000000000010_1.jpg
          .
          .





          share|improve this answer






















          • replace ._$file with _1.jpg and I think you've got it.
            – WinEunuuchs2Unix
            Mar 19 at 23:10










          • I edited my answer, I thought _1.jpg was supposed to be the original file name.
            – Paul
            Mar 19 at 23:57










          • Looking better. Just need to change ._1.jpg to _1.jpg then I think it's perfect.
            – WinEunuuchs2Unix
            Mar 20 at 1:48












          up vote
          2
          down vote










          up vote
          2
          down vote









          Would this works for you :



          i=1
          for file in *; do
          mv "$file" "$(printf %014d $i)_1.jpg"
          i=$((i+1))
          done


          It will rename every file in the current directory like this :



          00000000000001_1.jpg
          .
          .
          00000000000009_1.jpg
          .
          .
          00000000000010_1.jpg
          .
          .





          share|improve this answer














          Would this works for you :



          i=1
          for file in *; do
          mv "$file" "$(printf %014d $i)_1.jpg"
          i=$((i+1))
          done


          It will rename every file in the current directory like this :



          00000000000001_1.jpg
          .
          .
          00000000000009_1.jpg
          .
          .
          00000000000010_1.jpg
          .
          .






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 20 at 14:09

























          answered Mar 19 at 22:21









          Paul

          865




          865











          • replace ._$file with _1.jpg and I think you've got it.
            – WinEunuuchs2Unix
            Mar 19 at 23:10










          • I edited my answer, I thought _1.jpg was supposed to be the original file name.
            – Paul
            Mar 19 at 23:57










          • Looking better. Just need to change ._1.jpg to _1.jpg then I think it's perfect.
            – WinEunuuchs2Unix
            Mar 20 at 1:48
















          • replace ._$file with _1.jpg and I think you've got it.
            – WinEunuuchs2Unix
            Mar 19 at 23:10










          • I edited my answer, I thought _1.jpg was supposed to be the original file name.
            – Paul
            Mar 19 at 23:57










          • Looking better. Just need to change ._1.jpg to _1.jpg then I think it's perfect.
            – WinEunuuchs2Unix
            Mar 20 at 1:48















          replace ._$file with _1.jpg and I think you've got it.
          – WinEunuuchs2Unix
          Mar 19 at 23:10




          replace ._$file with _1.jpg and I think you've got it.
          – WinEunuuchs2Unix
          Mar 19 at 23:10












          I edited my answer, I thought _1.jpg was supposed to be the original file name.
          – Paul
          Mar 19 at 23:57




          I edited my answer, I thought _1.jpg was supposed to be the original file name.
          – Paul
          Mar 19 at 23:57












          Looking better. Just need to change ._1.jpg to _1.jpg then I think it's perfect.
          – WinEunuuchs2Unix
          Mar 20 at 1:48




          Looking better. Just need to change ._1.jpg to _1.jpg then I think it's perfect.
          – WinEunuuchs2Unix
          Mar 20 at 1:48


          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491