Translations of this page?:

VARIOUS Batch rename files in terminal

Whenever I convert from one file format to another (for example, flac → ogg), I use find and ffmpeg. However, that leaves me with files like song_1.flac.ogg which is really annoying. Since my music library is distributed among multiple folders, it would have been annoying to use Thunar's Bulk Renamer. That's why I put together the following script:

#!/bin/bash
find -name *.$1 | while read f
do
    mv ./"$f" "${f%$1}$2"
done
echo "Successful!"

(Yes, the last line is completely extraneous and completely meaningless in the context of error messages ;-)) The script takes two arguments - the first is the extension you want to remove and the second is the extension you want to replace it with. For example: To rename a bunch of files like song_1.flac.ogg, I'd call the script like this:

rename.sh flac.ogg ogg

Notice that I did not include a leading dot for either the first or second arguments.

That's it! Enjoy! :-D

 
howto/batch_rename_files_in_terminal.txt · Last modified: 2012/05/24 07:26 by machinebacon
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported

Powered by DokuWiki. Hosted by Linode.
Copyright © 2010 CrunchBang Linux.
Proudly powered by Debian GNU/Linux.
Debian is a registered trademark of Software in the Public Interest, Inc.