Batch convert files while retaining the name
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
New contributor
add a comment |
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
New contributor
add a comment |
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
New contributor
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
linux command-line bash calibre
New contributor
New contributor
edited Dec 26 at 21:34
New contributor
asked Dec 26 at 20:49
Tlink
154
154
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
( 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.
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 thecd
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 withfind
or with**
(aftershopt -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
|
show 4 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
( 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.
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 thecd
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 withfind
or with**
(aftershopt -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
|
show 4 more comments
( 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.
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 thecd
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 withfind
or with**
(aftershopt -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
|
show 4 more comments
( 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.
( 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.
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 thecd
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 withfind
or with**
(aftershopt -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
|
show 4 more comments
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 thecd
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 withfind
or with**
(aftershopt -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
|
show 4 more comments
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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