Rename all subtitles files with the same name of mp4 files in same folder

paste -d: <(ls -1 *.mp4) <(ls -1 *.srt) | while read line; do movie="${line%%:*}"; subtitle="${line##*:}"; mv "${subtitle}" "${movie%.*}.srt"; done
Use this command if you want to rename all subtitles for them to have the same name as the mp4 files. NOTE: The order of "ls -1 *.mp4" must match the order of "ls -1 *.srt", run the command bellow to make sure the *.srt files will really match the movies after run this command: paste -d:

0
2020-11-08 02:47:13

What Others Think

Shouldn't `echo $line be `echo "$line" ?
rautamiekka · 3 weeks and 4 days ago
@rautamiekka Actually no, because "echo" command will just print out all the contents of the variable, so it will never run into white space issues. But with the "mv" command we need it. I updated the command to be more reliable with white space in file names. I added the quotes anyway Best ;)
ricardofunke · 3 weeks and 3 days ago
We actually don't need no "echo" here... =/
ricardofunke · 3 weeks and 3 days ago
Tried this and deleted the subs from the folder. Fortunately, it was just 1 file but still.
Moltke · 3 weeks and 2 days ago
This so helpful for me now can easily convert the names of file and can exist different mp4 files with the same name Ecommerce web development dubai
Faisal · 3 weeks and 1 day ago
It does work! Thanks a lot for this! SEO companies Tampa
brielleluna · 3 weeks ago
this and deleted the subs from the folder. Fortunately, it was just [url=http://www.surecleanonline.co.uk/]surecleanonline.co.uk[/url] . [url=http://www.clearanceworld.org.uk/]clearanceworld.org.uk[/url] . [url=http://www.carpetcleaningproductorlando.us/]house clearances[/url] . [url=https://thefrisky.com/choosing-right-biohazard-clean-service/]biohazard cleaning[/url]
saeed20 · 3 weeks ago
guitar lessons spokane Wow! I did not know you can use ipad that way! This is interesting
yeoyeo · 2 weeks and 6 days ago
I really loved reading your blog. It was very well authored and easy to undertand. Unlike additional blogs I have read which are really not tht good. I also found your posts very interesting. In fact after reading. I had to go show it to my friend and he ejoyed it as well! ????
KayGasaway · 2 weeks and 5 days ago
This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. HOT MEN CAPS Mercado Livre
hiknigarde · 2 weeks and 4 days ago
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. best climber machine
KayGasaway · 2 weeks and 4 days ago
This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! ?????
KayGasaway · 2 weeks and 1 day ago
howdy, your websites are really good. I appreciate your work. SILDENAX
hiknigarde · 1 week and 6 days ago
This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! ?????
KayGasaway · 1 week and 4 days ago
great! works well. thanks for this fencingwichitaks.com
looneyhans · 1 week and 2 days ago
The book has a lot of knowledge, but not everyone wants to spend time writing an essay, and for this, I recommend you a wonderful site https://papernow.org/book-reports that will help you write any written work.
Shouressunt · 1 week ago
I'm constantly searching on the internet for posts that will help me. Too much is clearly to learn about this. I believe you created good quality items in Functions also. Keep working, congrats! CBD Nugs
KayGasaway · 1 week ago
this is really good! bathroomremodelboise.com
Killersmile · 6 days ago
Way to go! Great post thanks ! keep on posting! Seamless gutter installation
Chaddychaddy · 2 days ago
This is a very interesting blog post. welldrillingmidlandtx.com/well-maintenance-inspection
keywave110 · 10 hours ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: