Change extension of all file names containing specific string
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
When I get a file whose name contains the string "x264", I wish to change its extension to ".mp4" (for reasons too detailed to explain here). Examples:
Seinfeld_S02E05_x264.mkv
-> Seinfeld_S02E05_x264.mp4
Seinfeld_S02E05_x264.avi
-> Seinfeld_S02E05_x264.mp4
What script can I use to automatically make such a change? My computer is a NAS4FREE server running FreeBSD 11.1
UPDATE (after Jeff's response): I forgot to mention that I want this to work in the designated directory and all its sub-directories as well. Perhaps a command rather than a script?
files rename
add a comment |Â
up vote
0
down vote
favorite
When I get a file whose name contains the string "x264", I wish to change its extension to ".mp4" (for reasons too detailed to explain here). Examples:
Seinfeld_S02E05_x264.mkv
-> Seinfeld_S02E05_x264.mp4
Seinfeld_S02E05_x264.avi
-> Seinfeld_S02E05_x264.mp4
What script can I use to automatically make such a change? My computer is a NAS4FREE server running FreeBSD 11.1
UPDATE (after Jeff's response): I forgot to mention that I want this to work in the designated directory and all its sub-directories as well. Perhaps a command rather than a script?
files rename
Do you know? with this way you are losing your fileSeinfeld_S02E05_x264.mkv
? In your given sample you are rename two different files name to single name and first one will be deleted completely
â Ã±ÃÂsýù÷
Apr 19 at 14:34
I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion.
â Jim
Apr 20 at 2:03
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When I get a file whose name contains the string "x264", I wish to change its extension to ".mp4" (for reasons too detailed to explain here). Examples:
Seinfeld_S02E05_x264.mkv
-> Seinfeld_S02E05_x264.mp4
Seinfeld_S02E05_x264.avi
-> Seinfeld_S02E05_x264.mp4
What script can I use to automatically make such a change? My computer is a NAS4FREE server running FreeBSD 11.1
UPDATE (after Jeff's response): I forgot to mention that I want this to work in the designated directory and all its sub-directories as well. Perhaps a command rather than a script?
files rename
When I get a file whose name contains the string "x264", I wish to change its extension to ".mp4" (for reasons too detailed to explain here). Examples:
Seinfeld_S02E05_x264.mkv
-> Seinfeld_S02E05_x264.mp4
Seinfeld_S02E05_x264.avi
-> Seinfeld_S02E05_x264.mp4
What script can I use to automatically make such a change? My computer is a NAS4FREE server running FreeBSD 11.1
UPDATE (after Jeff's response): I forgot to mention that I want this to work in the designated directory and all its sub-directories as well. Perhaps a command rather than a script?
files rename
edited Apr 19 at 12:14
don_crissti
46.3k15123152
46.3k15123152
asked Apr 18 at 10:30
Jim
32
32
Do you know? with this way you are losing your fileSeinfeld_S02E05_x264.mkv
? In your given sample you are rename two different files name to single name and first one will be deleted completely
â Ã±ÃÂsýù÷
Apr 19 at 14:34
I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion.
â Jim
Apr 20 at 2:03
add a comment |Â
Do you know? with this way you are losing your fileSeinfeld_S02E05_x264.mkv
? In your given sample you are rename two different files name to single name and first one will be deleted completely
â Ã±ÃÂsýù÷
Apr 19 at 14:34
I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion.
â Jim
Apr 20 at 2:03
Do you know? with this way you are losing your file
Seinfeld_S02E05_x264.mkv
? In your given sample you are rename two different files name to single name and first one will be deleted completelyâ Ã±ÃÂsýù÷
Apr 19 at 14:34
Do you know? with this way you are losing your file
Seinfeld_S02E05_x264.mkv
? In your given sample you are rename two different files name to single name and first one will be deleted completelyâ Ã±ÃÂsýù÷
Apr 19 at 14:34
I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion.
â Jim
Apr 20 at 2:03
I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion.
â Jim
Apr 20 at 2:03
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
Using find
:
find -type f -name "*x264*" -execdir sh -c 'echo mv -n "$1" "$1%.*.mp4"' _ ;
The -n
option will prevent mv
to overwrite to existing files as your given samples files' name renaming to single file name and with this case you are are deleting first file.
To get this work on files without having extensions (suffix):
find -type f -name "*x264*" -execdir sh -c 'file="$1#./";
echo mv -n "$file" "$file%.*.mp4"' _ ;
remove echo
in above to get rid of dry-run and perform rename on files.
Thanks! This did the trick. I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion
â Jim
Apr 20 at 2:04
add a comment |Â
up vote
2
down vote
for f in *x264*.*
do
mv -- "$f" "$f%.*".mp4
done
The above runs a shell loop over a "glob" pattern that finds files with "x264" in their filename before some sort of extension (so that there's an extension to rename later); once it has that list of files, it calls mv
to do the rename, and uses parameter expansion to strip the extension (period followed by anything *
) then manually appends the .mp4
extension.
Note that hidden files (files whose name starts with.
) are not processed.
â Stéphane Chazelas
Apr 18 at 12:45
Indeed; seems ok for the assumed scenario. dotglob would toggle this behavior, if needed.
â Jeff Schaller
Apr 18 at 12:47
This will also do it for directories having x264 and dot in it's name.
â Bhagyesh Dudhediya
Apr 19 at 11:10
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Using find
:
find -type f -name "*x264*" -execdir sh -c 'echo mv -n "$1" "$1%.*.mp4"' _ ;
The -n
option will prevent mv
to overwrite to existing files as your given samples files' name renaming to single file name and with this case you are are deleting first file.
To get this work on files without having extensions (suffix):
find -type f -name "*x264*" -execdir sh -c 'file="$1#./";
echo mv -n "$file" "$file%.*.mp4"' _ ;
remove echo
in above to get rid of dry-run and perform rename on files.
Thanks! This did the trick. I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion
â Jim
Apr 20 at 2:04
add a comment |Â
up vote
0
down vote
accepted
Using find
:
find -type f -name "*x264*" -execdir sh -c 'echo mv -n "$1" "$1%.*.mp4"' _ ;
The -n
option will prevent mv
to overwrite to existing files as your given samples files' name renaming to single file name and with this case you are are deleting first file.
To get this work on files without having extensions (suffix):
find -type f -name "*x264*" -execdir sh -c 'file="$1#./";
echo mv -n "$file" "$file%.*.mp4"' _ ;
remove echo
in above to get rid of dry-run and perform rename on files.
Thanks! This did the trick. I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion
â Jim
Apr 20 at 2:04
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Using find
:
find -type f -name "*x264*" -execdir sh -c 'echo mv -n "$1" "$1%.*.mp4"' _ ;
The -n
option will prevent mv
to overwrite to existing files as your given samples files' name renaming to single file name and with this case you are are deleting first file.
To get this work on files without having extensions (suffix):
find -type f -name "*x264*" -execdir sh -c 'file="$1#./";
echo mv -n "$file" "$file%.*.mp4"' _ ;
remove echo
in above to get rid of dry-run and perform rename on files.
Using find
:
find -type f -name "*x264*" -execdir sh -c 'echo mv -n "$1" "$1%.*.mp4"' _ ;
The -n
option will prevent mv
to overwrite to existing files as your given samples files' name renaming to single file name and with this case you are are deleting first file.
To get this work on files without having extensions (suffix):
find -type f -name "*x264*" -execdir sh -c 'file="$1#./";
echo mv -n "$file" "$file%.*.mp4"' _ ;
remove echo
in above to get rid of dry-run and perform rename on files.
edited Apr 20 at 10:02
answered Apr 19 at 14:53
ñÃÂsýù÷
14.8k82462
14.8k82462
Thanks! This did the trick. I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion
â Jim
Apr 20 at 2:04
add a comment |Â
Thanks! This did the trick. I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion
â Jim
Apr 20 at 2:04
Thanks! This did the trick. I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion
â Jim
Apr 20 at 2:04
Thanks! This did the trick. I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion
â Jim
Apr 20 at 2:04
add a comment |Â
up vote
2
down vote
for f in *x264*.*
do
mv -- "$f" "$f%.*".mp4
done
The above runs a shell loop over a "glob" pattern that finds files with "x264" in their filename before some sort of extension (so that there's an extension to rename later); once it has that list of files, it calls mv
to do the rename, and uses parameter expansion to strip the extension (period followed by anything *
) then manually appends the .mp4
extension.
Note that hidden files (files whose name starts with.
) are not processed.
â Stéphane Chazelas
Apr 18 at 12:45
Indeed; seems ok for the assumed scenario. dotglob would toggle this behavior, if needed.
â Jeff Schaller
Apr 18 at 12:47
This will also do it for directories having x264 and dot in it's name.
â Bhagyesh Dudhediya
Apr 19 at 11:10
add a comment |Â
up vote
2
down vote
for f in *x264*.*
do
mv -- "$f" "$f%.*".mp4
done
The above runs a shell loop over a "glob" pattern that finds files with "x264" in their filename before some sort of extension (so that there's an extension to rename later); once it has that list of files, it calls mv
to do the rename, and uses parameter expansion to strip the extension (period followed by anything *
) then manually appends the .mp4
extension.
Note that hidden files (files whose name starts with.
) are not processed.
â Stéphane Chazelas
Apr 18 at 12:45
Indeed; seems ok for the assumed scenario. dotglob would toggle this behavior, if needed.
â Jeff Schaller
Apr 18 at 12:47
This will also do it for directories having x264 and dot in it's name.
â Bhagyesh Dudhediya
Apr 19 at 11:10
add a comment |Â
up vote
2
down vote
up vote
2
down vote
for f in *x264*.*
do
mv -- "$f" "$f%.*".mp4
done
The above runs a shell loop over a "glob" pattern that finds files with "x264" in their filename before some sort of extension (so that there's an extension to rename later); once it has that list of files, it calls mv
to do the rename, and uses parameter expansion to strip the extension (period followed by anything *
) then manually appends the .mp4
extension.
for f in *x264*.*
do
mv -- "$f" "$f%.*".mp4
done
The above runs a shell loop over a "glob" pattern that finds files with "x264" in their filename before some sort of extension (so that there's an extension to rename later); once it has that list of files, it calls mv
to do the rename, and uses parameter expansion to strip the extension (period followed by anything *
) then manually appends the .mp4
extension.
answered Apr 18 at 11:03
Jeff Schaller
31.1k846105
31.1k846105
Note that hidden files (files whose name starts with.
) are not processed.
â Stéphane Chazelas
Apr 18 at 12:45
Indeed; seems ok for the assumed scenario. dotglob would toggle this behavior, if needed.
â Jeff Schaller
Apr 18 at 12:47
This will also do it for directories having x264 and dot in it's name.
â Bhagyesh Dudhediya
Apr 19 at 11:10
add a comment |Â
Note that hidden files (files whose name starts with.
) are not processed.
â Stéphane Chazelas
Apr 18 at 12:45
Indeed; seems ok for the assumed scenario. dotglob would toggle this behavior, if needed.
â Jeff Schaller
Apr 18 at 12:47
This will also do it for directories having x264 and dot in it's name.
â Bhagyesh Dudhediya
Apr 19 at 11:10
Note that hidden files (files whose name starts with
.
) are not processed.â Stéphane Chazelas
Apr 18 at 12:45
Note that hidden files (files whose name starts with
.
) are not processed.â Stéphane Chazelas
Apr 18 at 12:45
Indeed; seems ok for the assumed scenario. dotglob would toggle this behavior, if needed.
â Jeff Schaller
Apr 18 at 12:47
Indeed; seems ok for the assumed scenario. dotglob would toggle this behavior, if needed.
â Jeff Schaller
Apr 18 at 12:47
This will also do it for directories having x264 and dot in it's name.
â Bhagyesh Dudhediya
Apr 19 at 11:10
This will also do it for directories having x264 and dot in it's name.
â Bhagyesh Dudhediya
Apr 19 at 11:10
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438476%2fchange-extension-of-all-file-names-containing-specific-string%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Do you know? with this way you are losing your file
Seinfeld_S02E05_x264.mkv
? In your given sample you are rename two different files name to single name and first one will be deleted completelyâ Ã±ÃÂsýù÷
Apr 19 at 14:34
I was showing the same filename twice just as an example of how I wanted the extension name changed no matter what the original extension name was. I should have given different filenames - sorry for the confusion.
â Jim
Apr 20 at 2:03