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 8 hours ago





















      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 9 hours ago









      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
            8 hours ago










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            8 hours ago










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            7 hours ago






          • 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
            7 hours ago






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            5 hours ago











          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
            8 hours ago










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            8 hours ago










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            7 hours ago






          • 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
            7 hours ago






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            5 hours ago
















          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
            8 hours ago










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            8 hours ago










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            7 hours ago






          • 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
            7 hours ago






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            5 hours ago














          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 7 hours ago

























          answered 9 hours ago









          Kamil Maciorowski

          23.9k155175




          23.9k155175












          • Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
            – Tlink
            8 hours ago










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            8 hours ago










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            7 hours ago






          • 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
            7 hours ago






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            5 hours ago


















          • Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
            – Tlink
            8 hours ago










          • Does the sub-shell just avoid having the cd be permanent?
            – Xen2050
            8 hours ago










          • Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
            – Tlink
            7 hours ago






          • 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
            7 hours ago






          • 1




            @Tlink you should be accepting the answer anyway, instead of merely upvoting it
            – George M
            5 hours ago
















          Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
          – Tlink
          8 hours ago




          Thanks for the answer, I wish I could up vote it, but I don't have enough reputations .
          – Tlink
          8 hours ago












          Does the sub-shell just avoid having the cd be permanent?
          – Xen2050
          8 hours ago




          Does the sub-shell just avoid having the cd be permanent?
          – Xen2050
          8 hours ago












          Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
          – Tlink
          7 hours ago




          Do I have to add anything to make the command work recursively on sub folders? find ~/book -name '*.epub' -exec ...........?
          – Tlink
          7 hours ago




          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
          7 hours ago




          @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
          7 hours ago




          1




          1




          @Tlink you should be accepting the answer anyway, instead of merely upvoting it
          – George M
          5 hours ago




          @Tlink you should be accepting the answer anyway, instead of merely upvoting it
          – George M
          5 hours ago










          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

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          How to ignore python UserWarning in pytest?

          Alexandru Averescu