I want to rename all files in a directory from *.ts to *.mkv
Rename all the files in .ts files in a directory
My echo command works but not if I try to make it a new variable.
#!/bin/sh
for file in "${1}"/*.ts; do
echo ${file} | sed -e 's|.ts|.mkv|'
new_name=${file} | sed -e 's|.ts|.mkv|'
done
shell-script files rename
New contributor
add a comment |
Rename all the files in .ts files in a directory
My echo command works but not if I try to make it a new variable.
#!/bin/sh
for file in "${1}"/*.ts; do
echo ${file} | sed -e 's|.ts|.mkv|'
new_name=${file} | sed -e 's|.ts|.mkv|'
done
shell-script files rename
New contributor
Just userename
. If the Perl version, it's justrename 's/.ts$/.mkv' *
.
– Sparhawk
4 hours ago
5
Possible duplicate of Changing extension to multiple files
– Jeff Schaller
3 hours ago
I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory
– NasKar
2 hours ago
1
Please edit your question to include this information.
– Sparhawk
2 hours ago
add a comment |
Rename all the files in .ts files in a directory
My echo command works but not if I try to make it a new variable.
#!/bin/sh
for file in "${1}"/*.ts; do
echo ${file} | sed -e 's|.ts|.mkv|'
new_name=${file} | sed -e 's|.ts|.mkv|'
done
shell-script files rename
New contributor
Rename all the files in .ts files in a directory
My echo command works but not if I try to make it a new variable.
#!/bin/sh
for file in "${1}"/*.ts; do
echo ${file} | sed -e 's|.ts|.mkv|'
new_name=${file} | sed -e 's|.ts|.mkv|'
done
shell-script files rename
shell-script files rename
New contributor
New contributor
edited 4 hours ago
Jeff Schaller
40.1k1054126
40.1k1054126
New contributor
asked 4 hours ago
NasKarNasKar
61
61
New contributor
New contributor
Just userename
. If the Perl version, it's justrename 's/.ts$/.mkv' *
.
– Sparhawk
4 hours ago
5
Possible duplicate of Changing extension to multiple files
– Jeff Schaller
3 hours ago
I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory
– NasKar
2 hours ago
1
Please edit your question to include this information.
– Sparhawk
2 hours ago
add a comment |
Just userename
. If the Perl version, it's justrename 's/.ts$/.mkv' *
.
– Sparhawk
4 hours ago
5
Possible duplicate of Changing extension to multiple files
– Jeff Schaller
3 hours ago
I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory
– NasKar
2 hours ago
1
Please edit your question to include this information.
– Sparhawk
2 hours ago
Just use
rename
. If the Perl version, it's just rename 's/.ts$/.mkv' *
.– Sparhawk
4 hours ago
Just use
rename
. If the Perl version, it's just rename 's/.ts$/.mkv' *
.– Sparhawk
4 hours ago
5
5
Possible duplicate of Changing extension to multiple files
– Jeff Schaller
3 hours ago
Possible duplicate of Changing extension to multiple files
– Jeff Schaller
3 hours ago
I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory
– NasKar
2 hours ago
I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory
– NasKar
2 hours ago
1
1
Please edit your question to include this information.
– Sparhawk
2 hours ago
Please edit your question to include this information.
– Sparhawk
2 hours ago
add a comment |
3 Answers
3
active
oldest
votes
The simplest solution would be to tell you to change the assignment to:
new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )
But a better solution would be to do:
new_name="${file%.ts}.mkv"
add a comment |
#!/bin/sh
for file in "${1}"/*.ts; do
mv "${file}" "$(basename "${file}").mkv"
done
add a comment |
find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"
Run this in the directory containing the .ts
files.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
NasKar 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%2funix.stackexchange.com%2fquestions%2f497101%2fi-want-to-rename-all-files-in-a-directory-from-ts-to-mkv%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The simplest solution would be to tell you to change the assignment to:
new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )
But a better solution would be to do:
new_name="${file%.ts}.mkv"
add a comment |
The simplest solution would be to tell you to change the assignment to:
new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )
But a better solution would be to do:
new_name="${file%.ts}.mkv"
add a comment |
The simplest solution would be to tell you to change the assignment to:
new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )
But a better solution would be to do:
new_name="${file%.ts}.mkv"
The simplest solution would be to tell you to change the assignment to:
new_name=$( echo ${file} | sed -e 's|.ts|.mkv|' )
But a better solution would be to do:
new_name="${file%.ts}.mkv"
answered 2 hours ago
IsaacIsaac
11.7k11752
11.7k11752
add a comment |
add a comment |
#!/bin/sh
for file in "${1}"/*.ts; do
mv "${file}" "$(basename "${file}").mkv"
done
add a comment |
#!/bin/sh
for file in "${1}"/*.ts; do
mv "${file}" "$(basename "${file}").mkv"
done
add a comment |
#!/bin/sh
for file in "${1}"/*.ts; do
mv "${file}" "$(basename "${file}").mkv"
done
#!/bin/sh
for file in "${1}"/*.ts; do
mv "${file}" "$(basename "${file}").mkv"
done
answered 2 hours ago
nyetnyet
13113
13113
add a comment |
add a comment |
find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"
Run this in the directory containing the .ts
files.
add a comment |
find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"
Run this in the directory containing the .ts
files.
add a comment |
find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"
Run this in the directory containing the .ts
files.
find . -maxdepth 1 -type f -name '*.ts' -exec rename .ts .mkv {} "+"
Run this in the directory containing the .ts
files.
answered 26 mins ago
Niko GambtNiko Gambt
1406
1406
add a comment |
add a comment |
NasKar is a new contributor. Be nice, and check out our Code of Conduct.
NasKar is a new contributor. Be nice, and check out our Code of Conduct.
NasKar is a new contributor. Be nice, and check out our Code of Conduct.
NasKar is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f497101%2fi-want-to-rename-all-files-in-a-directory-from-ts-to-mkv%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
Just use
rename
. If the Perl version, it's justrename 's/.ts$/.mkv' *
.– Sparhawk
4 hours ago
5
Possible duplicate of Changing extension to multiple files
– Jeff Schaller
3 hours ago
I want to save the renamed file to a variable to pass in another command in the script (input name -> output name). The examples are for renaming them in the directory
– NasKar
2 hours ago
1
Please edit your question to include this information.
– Sparhawk
2 hours ago