7

I have a bunch of wav files I converted to mp3 files using ffmpeg.

Now the mp3 files are all named file.wav.mp3.

How can I remove the .wav suffix while keeping the rest of the file name? I would like to do this on a whole directory at once.

20

With a shell loop, removing the shortest "double dot suffix"

for f in *.wav.mp3; do echo mv "$f" "${f%.*.*}.mp3"; done

or (my personal favorite for things like this) with mmv from package mmv

mmv -n '*.wav.mp3' '#1.mp3'

Remove the echo or the -n as appropriate once you are happy that they are doing the right thing.

| improve this answer | |
  • thanks, i like the mmv option. really simple – un_armed_pawn Jul 29 at 20:23
  • If you are using zsh, zmv is also great. – 0x5453 Jul 31 at 12:39
  • I always recommend using mv -n or -i for bulk/automated renames like this, to avoid the possibility of silently & irreversibly deleting files if there's a name conflict. – Gordon Davisson Jul 31 at 22:25
19

Read man rename and do something like:

rename 's/.wav.mp3/.mp3/' *.wav.mp3

You may have to sudo apt install rename, first.

| improve this answer | |
  • 3
    For this to work, you should install the rename package first. It is not installed by default. – Puspam Jul 29 at 19:54
  • 6
    ... perhaps s/\.wav\.mp3$/.mp3/ to err on the safe side...? – steeldriver Jul 29 at 19:54
  • 1
    I included an example in my answer. Didn't that help? – waltinator Jul 29 at 20:07
  • 6
    I recommend always running rename with the -n option first to see what it will do, then removing -n once one is satisfied. – Eliah Kagan Jul 29 at 20:26
7

In the file browser in Ubuntu, you can select multiple files and rename them according to a pattern by just hitting F2 or right-clicking and selecting Rename.

Here I am replacing x with _by_. In your case you can replace .wav with an empty string.

rename multiple files in Ubuntu

| improve this answer | |
  • Thanks Mr Felix U for this tip. I have been using RANGER for this operation for a long time. But this is much simpler. – elmclose Jul 30 at 18:37
4

As you can see there are multiple ways to achieve this. Another way using the basename command is shown below:

for file in ./*.wav.mp3
do
    mv "$file" "$(basename "$file" .wav.mp3)".mp3 
done
| improve this answer | |
  • @steeldriver Thank you for pointing to this nice article. I have updated the answer accordingly. – turbulence Jul 30 at 3:56
  • 2
    I added quotes around the command substitution as well - remember, if $file contains whitespace, then basename "$file" .wav.mp3 will as well. – steeldriver Jul 30 at 10:51
2

If you have all the files named in .wav.mp3 format, then use the following command:

for i in *.wav.mp3; do echo $i; mv "$i" "${i::-8}.mp3"; done
| improve this answer | |
  • 1
    String manipulation takes negative values so "${i::-8}.mp3" should generate same result. Better to quote the whole string than to concat the strings – bac0n Jul 30 at 5:53
  • Thanks for the suggestion. I have edited it. – Puspam Jul 30 at 9:54
1

When in the directory with the .wav.mp3 files:

for i in *.wav.mp3; do mv "$i" "$(echo $i | sed s/.wav//g)"; done

That said, you may be able to use the same for your ffmpeg command so you don't have to rename them later.

| improve this answer | |
0

I just want to add a tool tip:

A real nice program for such tasks is emv.

You run it as `emv .wav.mp3 and it opens an editor. You can then use search & replace. Then you save the file and close the editor and the program renames your files.

This is especially handy, when you know how to use an advanced editor like vim, but even when most simple editors support search & replace, what is what you usually need for problems like yours.

| improve this answer | |
0
#!/bin/bash
for i in *
do
 #Define the string value
 text="$i"

 # Set .wav as the delimiter
 IFS='.wav.'

 #Read the split words into an array based on space delimiter
read -a strarr <<< "$text"
mv "$i" "${strarr[0]).mp3" #changing input file name


done
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.