LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-31-2018, 03:53 PM   #1
cranon
LQ Newbie
 
Registered: Nov 2018
Posts: 6

Rep: Reputation: 0
Bulk renaming music files to <songname>.ext


I have a bunch of music files. All the metadata tags are correct but the naming of the files is bad. How should i go about bulk renaming all my music files to songname.ext
 
Old 12-31-2018, 09:08 PM   #2
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,972

Rep: Reputation: 271Reputation: 271Reputation: 271
Extract the title from the file's tags with id3tool or id3info or mediainfo (what I use), use that to rename the file.
Code:
for file in *.mp3
do
Title=`id3tool $file | grep "Song Title:" | cut -d: -f2 | tr ' ' '_'`
mv $file "$Title".mp3
done
If you can tolerate spaces in file names you can omit the last step. I don't like either so I capitalize all first letters, which is more complicated.
 
Old 12-31-2018, 09:28 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Quote:
Originally Posted by cranon View Post
IHow should i go about bulk renaming all my music files to songname.ext
Veryyyy carefully.
I might be inclined to echo that mv command before committing the deed ...
 
1 members found this post helpful.
Old 12-31-2018, 11:28 PM   #4
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,972

Rep: Reputation: 271Reputation: 271Reputation: 271
Quote:
Originally Posted by syg00 View Post
Veryyyy carefully.
I might be inclined to echo that mv command before committing the deed ...
Yes! I've screwed up in the past. For something like this, I run it with echo first to see what it looks like. I would also use 'mv -n' to make sure I didn't overwrite anything. Maybe I'd make the target another, empty, directory to look at the results first.

Note that the programs I recommend to extract the name have leading spaces, which would leave the target name with a lot of leading _ if you convert spaces to _s. I do this a lot and have a renaming routine that strips leading spaces, punctuation marks, metacharacters (such as ()*?/\), uppercases the first letter of each word, leaving a space-less, punctuation-less, camel-case target name. It also converts UTF and HTML metacharacters to ASCII-closest so all file names are ASCII. (I have classical music and use diacritical marks in tags but not file names.)
 
Old 01-10-2019, 07:16 PM   #5
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by cranon View Post
I have a bunch of music files. All the metadata tags are correct but the naming of the files is bad. How should i go about bulk renaming all my music files to songname.ext
I have used:

Code:
#!/bin/bash

for i in ./*old_string*; do mv -- "$i" "${i//old_string/new_string_here}"; done
doing just want you are looking for. This will leave the extension the same and take a file named:

foo.blah.jusnk.werlqjewrpoyuqewhjqwekrhjk.ext and move it to nice.file.name.ext
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Bulk renaming files jazziao Linux - Newbie 4 02-10-2015 01:08 PM
[SOLVED] Moving files, on shell, auto-renaming in a "basename(##).ext" pattern? the dsc Programming 7 12-02-2013 01:43 PM
Seeking a good bulk file renaming program 3lud13 Linux - Software 2 10-07-2012 12:07 PM
Filesystems: ext 2, ext 3, reiserfs. Which one? r3dhatter Linux - Newbie 12 07-15-2004 12:53 AM
Bulk File Renaming nevereverend Linux - Newbie 11 07-03-2004 05:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration