When using * in bash how do I output to the same file

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








up vote
0
down vote

favorite












I'm trying to use the command convert -resize 1024X768 source.png dest.jpg on a sequence of images. I need it to be applied to all the images which I can do by convert -resize 1024X768 *.png but I'd like to know how to supply the same filename as the destination.



I'm only using the convert command as an example.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I'm trying to use the command convert -resize 1024X768 source.png dest.jpg on a sequence of images. I need it to be applied to all the images which I can do by convert -resize 1024X768 *.png but I'd like to know how to supply the same filename as the destination.



    I'm only using the convert command as an example.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to use the command convert -resize 1024X768 source.png dest.jpg on a sequence of images. I need it to be applied to all the images which I can do by convert -resize 1024X768 *.png but I'd like to know how to supply the same filename as the destination.



      I'm only using the convert command as an example.










      share|improve this question















      I'm trying to use the command convert -resize 1024X768 source.png dest.jpg on a sequence of images. I need it to be applied to all the images which I can do by convert -resize 1024X768 *.png but I'd like to know how to supply the same filename as the destination.



      I'm only using the convert command as an example.







      bash






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 11 at 0:01

























      asked Mar 9 at 22:16









      user3927312

      1094




      1094




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          You can try with a for command line



          Test with a 'dry run',



          for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done


          and when its output looks good, remove echo and do the conversion,



          for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done


          Alternative with find and rename



          If you want to avoid a loop in bash, you can use find,



          find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;


          and when its output looks good, remove echo and do the conversion,



          find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;


          After that you can use rename to make the target file names nicer (prune the clumsy double extension)



          rename -n s/.png.jpg$/.jpg/ *.png.jpg


          and when its output looks good, remove -n and do the real renaming,



          rename s/.png.jpg$/.jpg/ *.png.jpg


          There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.






          share|improve this answer






















          • I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
            – user3927312
            Mar 10 at 1:15










          • @user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
            – sudodus
            Mar 10 at 8:17










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          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',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1013526%2fwhen-using-in-bash-how-do-i-output-to-the-same-file%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote



          accepted










          You can try with a for command line



          Test with a 'dry run',



          for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done


          and when its output looks good, remove echo and do the conversion,



          for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done


          Alternative with find and rename



          If you want to avoid a loop in bash, you can use find,



          find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;


          and when its output looks good, remove echo and do the conversion,



          find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;


          After that you can use rename to make the target file names nicer (prune the clumsy double extension)



          rename -n s/.png.jpg$/.jpg/ *.png.jpg


          and when its output looks good, remove -n and do the real renaming,



          rename s/.png.jpg$/.jpg/ *.png.jpg


          There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.






          share|improve this answer






















          • I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
            – user3927312
            Mar 10 at 1:15










          • @user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
            – sudodus
            Mar 10 at 8:17














          up vote
          6
          down vote



          accepted










          You can try with a for command line



          Test with a 'dry run',



          for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done


          and when its output looks good, remove echo and do the conversion,



          for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done


          Alternative with find and rename



          If you want to avoid a loop in bash, you can use find,



          find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;


          and when its output looks good, remove echo and do the conversion,



          find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;


          After that you can use rename to make the target file names nicer (prune the clumsy double extension)



          rename -n s/.png.jpg$/.jpg/ *.png.jpg


          and when its output looks good, remove -n and do the real renaming,



          rename s/.png.jpg$/.jpg/ *.png.jpg


          There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.






          share|improve this answer






















          • I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
            – user3927312
            Mar 10 at 1:15










          • @user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
            – sudodus
            Mar 10 at 8:17












          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          You can try with a for command line



          Test with a 'dry run',



          for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done


          and when its output looks good, remove echo and do the conversion,



          for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done


          Alternative with find and rename



          If you want to avoid a loop in bash, you can use find,



          find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;


          and when its output looks good, remove echo and do the conversion,



          find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;


          After that you can use rename to make the target file names nicer (prune the clumsy double extension)



          rename -n s/.png.jpg$/.jpg/ *.png.jpg


          and when its output looks good, remove -n and do the real renaming,



          rename s/.png.jpg$/.jpg/ *.png.jpg


          There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.






          share|improve this answer














          You can try with a for command line



          Test with a 'dry run',



          for i in *.png;do echo convert -resize 1024X768 "$i" "$i/.png.jpg";done


          and when its output looks good, remove echo and do the conversion,



          for i in *.png;do convert -resize 1024X768 "$i" "$i/.png.jpg";done


          Alternative with find and rename



          If you want to avoid a loop in bash, you can use find,



          find -maxdepth 1 -name "*.png" -exec echo convert -resize 1024X768 .jpg ;


          and when its output looks good, remove echo and do the conversion,



          find -maxdepth 1 -name "*.png" -exec convert -resize 1024X768 .jpg ;


          After that you can use rename to make the target file names nicer (prune the clumsy double extension)



          rename -n s/.png.jpg$/.jpg/ *.png.jpg


          and when its output looks good, remove -n and do the real renaming,



          rename s/.png.jpg$/.jpg/ *.png.jpg


          There are probably ways to do this in one step (without renaming), but I don't know how. Maybe someone will chip in and describe a way to do it.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 10 at 8:50

























          answered Mar 9 at 22:39









          sudodus

          20.4k32668




          20.4k32668











          • I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
            – user3927312
            Mar 10 at 1:15










          • @user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
            – sudodus
            Mar 10 at 8:17
















          • I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
            – user3927312
            Mar 10 at 1:15










          • @user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
            – sudodus
            Mar 10 at 8:17















          I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
          – user3927312
          Mar 10 at 1:15




          I was wondering if there was a way to do it without a loop. Perhaps some fancy bash thing.
          – user3927312
          Mar 10 at 1:15












          @user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
          – sudodus
          Mar 10 at 8:17




          @user3927312, An alternative without an explicit loop is to use find and rename. I can add it to the answer, but I think the for loop is more straightforward.
          – sudodus
          Mar 10 at 8:17

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1013526%2fwhen-using-in-bash-how-do-i-output-to-the-same-file%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491