Batch convert files while retaining the name












2














I want to use the following command to convert ebooks from epub format to mobi format:
calibre-convert books/*.epub books/*.mobi



but i want to retain the same file name for all the files.
So book1.epub will create book1.mobi
book2.epub will create book2.mobi after conversion.
is this doable in the command line? or do i have to write a bash script?










share|improve this question









New contributor




Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    2














    I want to use the following command to convert ebooks from epub format to mobi format:
    calibre-convert books/*.epub books/*.mobi



    but i want to retain the same file name for all the files.
    So book1.epub will create book1.mobi
    book2.epub will create book2.mobi after conversion.
    is this doable in the command line? or do i have to write a bash script?










    share|improve this question









    New contributor




    Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      2












      2








      2







      I want to use the following command to convert ebooks from epub format to mobi format:
      calibre-convert books/*.epub books/*.mobi



      but i want to retain the same file name for all the files.
      So book1.epub will create book1.mobi
      book2.epub will create book2.mobi after conversion.
      is this doable in the command line? or do i have to write a bash script?










      share|improve this question









      New contributor




      Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I want to use the following command to convert ebooks from epub format to mobi format:
      calibre-convert books/*.epub books/*.mobi



      but i want to retain the same file name for all the files.
      So book1.epub will create book1.mobi
      book2.epub will create book2.mobi after conversion.
      is this doable in the command line? or do i have to write a bash script?







      linux command-line bash calibre






      share|improve this question









      New contributor




      Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Dec 26 at 21:34





















      New contributor




      Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Dec 26 at 20:49









      Tlink

      154




      154




      New contributor




      Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Tlink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          6














          ( cd books && for file in *.epub; do calibre-convert "$file" "${file%epub}mobi"; done )


          The main trick here is ${file%epub} which means "$file with epub at the end removed". This way ${file%epub}mobi translates the extension.



          A subshell ((…)) is used so




          • the current working directory of the main shell stays intact

          • and the file variable in the main shell doesn't change.


          Any directory that matches *.epub in books/ will be passed to calibre-convert as well. It's up to the tool what it will do with the directory. You probably have no such directory there; but if you do, be warned.



          Note: I don't know calibre-convert at all; the syntax in my command is simply derived from your command.






          share|improve this answer























          • Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
            – Tlink
            Dec 26 at 21:32










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            Dec 26 at 22:13










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            Dec 26 at 22:27






          • 1




            @Tlink It's possible to do this recursively with find or with ** (after shopt -s globstar in Bash). Formal note though: the example in your question is not recursive and my answer keeps things this way. Substantially changing the question after any answer is published (and upvoted, and even accepted by you) is not a good practice here. In my opinion a separate question will be good, where you explicitly ask for a recursive solution (maybe link to this question to provide context, but even then the new question should be standalone).
            – Kamil Maciorowski
            Dec 26 at 22:45






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            Dec 27 at 0:57











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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
          });


          }
          });






          Tlink is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1387934%2fbatch-convert-files-while-retaining-the-name%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6














          ( cd books && for file in *.epub; do calibre-convert "$file" "${file%epub}mobi"; done )


          The main trick here is ${file%epub} which means "$file with epub at the end removed". This way ${file%epub}mobi translates the extension.



          A subshell ((…)) is used so




          • the current working directory of the main shell stays intact

          • and the file variable in the main shell doesn't change.


          Any directory that matches *.epub in books/ will be passed to calibre-convert as well. It's up to the tool what it will do with the directory. You probably have no such directory there; but if you do, be warned.



          Note: I don't know calibre-convert at all; the syntax in my command is simply derived from your command.






          share|improve this answer























          • Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
            – Tlink
            Dec 26 at 21:32










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            Dec 26 at 22:13










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            Dec 26 at 22:27






          • 1




            @Tlink It's possible to do this recursively with find or with ** (after shopt -s globstar in Bash). Formal note though: the example in your question is not recursive and my answer keeps things this way. Substantially changing the question after any answer is published (and upvoted, and even accepted by you) is not a good practice here. In my opinion a separate question will be good, where you explicitly ask for a recursive solution (maybe link to this question to provide context, but even then the new question should be standalone).
            – Kamil Maciorowski
            Dec 26 at 22:45






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            Dec 27 at 0:57
















          6














          ( cd books && for file in *.epub; do calibre-convert "$file" "${file%epub}mobi"; done )


          The main trick here is ${file%epub} which means "$file with epub at the end removed". This way ${file%epub}mobi translates the extension.



          A subshell ((…)) is used so




          • the current working directory of the main shell stays intact

          • and the file variable in the main shell doesn't change.


          Any directory that matches *.epub in books/ will be passed to calibre-convert as well. It's up to the tool what it will do with the directory. You probably have no such directory there; but if you do, be warned.



          Note: I don't know calibre-convert at all; the syntax in my command is simply derived from your command.






          share|improve this answer























          • Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
            – Tlink
            Dec 26 at 21:32










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            Dec 26 at 22:13










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            Dec 26 at 22:27






          • 1




            @Tlink It's possible to do this recursively with find or with ** (after shopt -s globstar in Bash). Formal note though: the example in your question is not recursive and my answer keeps things this way. Substantially changing the question after any answer is published (and upvoted, and even accepted by you) is not a good practice here. In my opinion a separate question will be good, where you explicitly ask for a recursive solution (maybe link to this question to provide context, but even then the new question should be standalone).
            – Kamil Maciorowski
            Dec 26 at 22:45






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            Dec 27 at 0:57














          6












          6








          6






          ( cd books && for file in *.epub; do calibre-convert "$file" "${file%epub}mobi"; done )


          The main trick here is ${file%epub} which means "$file with epub at the end removed". This way ${file%epub}mobi translates the extension.



          A subshell ((…)) is used so




          • the current working directory of the main shell stays intact

          • and the file variable in the main shell doesn't change.


          Any directory that matches *.epub in books/ will be passed to calibre-convert as well. It's up to the tool what it will do with the directory. You probably have no such directory there; but if you do, be warned.



          Note: I don't know calibre-convert at all; the syntax in my command is simply derived from your command.






          share|improve this answer














          ( cd books && for file in *.epub; do calibre-convert "$file" "${file%epub}mobi"; done )


          The main trick here is ${file%epub} which means "$file with epub at the end removed". This way ${file%epub}mobi translates the extension.



          A subshell ((…)) is used so




          • the current working directory of the main shell stays intact

          • and the file variable in the main shell doesn't change.


          Any directory that matches *.epub in books/ will be passed to calibre-convert as well. It's up to the tool what it will do with the directory. You probably have no such directory there; but if you do, be warned.



          Note: I don't know calibre-convert at all; the syntax in my command is simply derived from your command.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 26 at 23:04

























          answered Dec 26 at 21:06









          Kamil Maciorowski

          24.5k155277




          24.5k155277












          • Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
            – Tlink
            Dec 26 at 21:32










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            Dec 26 at 22:13










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            Dec 26 at 22:27






          • 1




            @Tlink It's possible to do this recursively with find or with ** (after shopt -s globstar in Bash). Formal note though: the example in your question is not recursive and my answer keeps things this way. Substantially changing the question after any answer is published (and upvoted, and even accepted by you) is not a good practice here. In my opinion a separate question will be good, where you explicitly ask for a recursive solution (maybe link to this question to provide context, but even then the new question should be standalone).
            – Kamil Maciorowski
            Dec 26 at 22:45






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            Dec 27 at 0:57


















          • Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
            – Tlink
            Dec 26 at 21:32










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            Dec 26 at 22:13










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            Dec 26 at 22:27






          • 1




            @Tlink It's possible to do this recursively with find or with ** (after shopt -s globstar in Bash). Formal note though: the example in your question is not recursive and my answer keeps things this way. Substantially changing the question after any answer is published (and upvoted, and even accepted by you) is not a good practice here. In my opinion a separate question will be good, where you explicitly ask for a recursive solution (maybe link to this question to provide context, but even then the new question should be standalone).
            – Kamil Maciorowski
            Dec 26 at 22:45






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            Dec 27 at 0:57
















          Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
          – Tlink
          Dec 26 at 21:32




          Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
          – Tlink
          Dec 26 at 21:32












          Does the sub-shell just avoid having the cd be permanent?
          – Xen2050
          Dec 26 at 22:13




          Does the sub-shell just avoid having the cd be permanent?
          – Xen2050
          Dec 26 at 22:13












          Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
          – Tlink
          Dec 26 at 22:27




          Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
          – Tlink
          Dec 26 at 22:27




          1




          1




          @Tlink It's possible to do this recursively with find or with ** (after shopt -s globstar in Bash). Formal note though: the example in your question is not recursive and my answer keeps things this way. Substantially changing the question after any answer is published (and upvoted, and even accepted by you) is not a good practice here. In my opinion a separate question will be good, where you explicitly ask for a recursive solution (maybe link to this question to provide context, but even then the new question should be standalone).
          – Kamil Maciorowski
          Dec 26 at 22:45




          @Tlink It's possible to do this recursively with find or with ** (after shopt -s globstar in Bash). Formal note though: the example in your question is not recursive and my answer keeps things this way. Substantially changing the question after any answer is published (and upvoted, and even accepted by you) is not a good practice here. In my opinion a separate question will be good, where you explicitly ask for a recursive solution (maybe link to this question to provide context, but even then the new question should be standalone).
          – Kamil Maciorowski
          Dec 26 at 22:45




          1




          1




          @Tlink you should be accepting the answer anyway, instead of merely upvoting it
          – George M
          Dec 27 at 0:57




          @Tlink you should be accepting the answer anyway, instead of merely upvoting it
          – George M
          Dec 27 at 0:57










          Tlink is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Tlink is a new contributor. Be nice, and check out our Code of Conduct.













          Tlink is a new contributor. Be nice, and check out our Code of Conduct.












          Tlink is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Super User!


          • 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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2fsuperuser.com%2fquestions%2f1387934%2fbatch-convert-files-while-retaining-the-name%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

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар