0

This question already has an answer here:

I have a folder with multiple files in it, and I want to append .mp3 extension at end of each file. is there any way to rename all these files with one command.?

marked as duplicate by Sylvain Pineau, terdon, αғsнιη, karel, Eric Carvalho Mar 31 '15 at 15:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Do the files already have an extenson? – Carl H Mar 31 '15 at 10:45
  • @carl no file doesn't have any extension. – piyushmandovra Mar 31 '15 at 10:53
  • ya dude but i don't have much experience with command line – piyushmandovra Mar 31 '15 at 11:09
  • 1
    ?? Your question is asking for a command line solution. – Jacob Vlijm Mar 31 '15 at 11:11
  • 1
    @JacobVlijm yes, but I post above comment because they say that my question is duplicate of some question. – piyushmandovra Mar 31 '15 at 11:15
8

Assuming the files don't already have any extension at all, then run this from the directory containing the files :-

for file in * ; do mv "$file" "$file".mp3; done 

If you want to be extra safe, do this instead :-

for file in * ; do cp "$file" "$file".mp3; done 

This will make copies of the files and add .mp3, instead of renaming them. You can always delete the originals afterwards.

Or if you want a graphical interface for mass renaming of files, then have a look at PyRenamer in the Software Centre.

  • is there any way to just rename instead of creating duplicates.? and out of curiosity is it shell scripting... ? – piyushmandovra Mar 31 '15 at 10:56
  • 1
    @piyushmandovra Yes, that's what the first part of my answer does - for file in * ; do mv "$file" "$file".mp3; done will rename every file to file.mp3. – Carl H Mar 31 '15 at 10:59
3

and I want to append .mp3 extension at end of each file

short command

for f in *; do mv "$f" "$f.mp3"; done
  • You beat Carl by a minute, but he got a better score... ;-) – Fabby Aug 10 '15 at 15:12
3

Use the command rename. It allows perl regexpes. E.g.,

rename 's/(.*)/$1.mp3/' *

Will add ".mp3" to the end of any file or directory name in the directory.

  • 1
    Is capturing and backsubstitution really necessary here? what about just s/$/.mp3/? – steeldriver Mar 31 '15 at 11:23

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