LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 12-16-2008, 05:51 AM   #1
ashrafulkarim
LQ Newbie
 
Registered: Nov 2008
Posts: 5

Rep: Reputation: 0
shell command for bulk 'rename'


Hi
I have a list of mp3 files which dont have extension at the end. I want to add the extension .mp3, by a shell command or small script. plz help.
more - is it possible to rename the files as Artist-Title etc extracting from mp3 tag?

/ashraf
 
Old 12-16-2008, 06:07 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,607
Blog Entries: 1

Rep: Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047Reputation: 1047
Before you do anything, backup your mp3 collection (just in case)
You should be in the directory where the mp3 files are and create a script:

Code:
for i in *
do
mv $i $i.mp3
done
You need to grant exec permissions:
Code:
chmod +x myscript
Finally you can run it:
Code:
./myscript
 
Old 12-16-2008, 06:14 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
To add an extension you can simply concatenate it to the original filename using a for loop. For example, suppose you have all (and only) the mp3 files in a given directory, you can do something like
Code:
cd /path/to/dir
for file in *
do
  mv "$file" "$file".mp3
done
do some tests on dummy files (or copies of the originals) before actually run the mv command. For the renaming part using information from the mp3 tags, I suggest eyeD3. For example the command
Code:
eyeD3 --rename="%A - %t" $FILE
will rename the mp3 file using Artist and Title taken from the tag. Take a look at the manual page for other useful format specifications.

Edit: sycamorex beat me! Anyway, I embedded $file within double quotes to manage file names with blank spaces (very common for mp3s).

Last edited by colucix; 12-16-2008 at 06:19 AM.
 
Old 12-16-2008, 06:16 AM   #4
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
ls | xargs -ifile mv file file.mp3
 
Old 12-17-2008, 04:44 AM   #5
ashrafulkarim
LQ Newbie
 
Registered: Nov 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks a lot to you all for the tip. really in the folder there are some file with .mp3 extension and there are some without the mp3 extension. some players like kaffeine dont take the files without mp3 extension in the playlist automatically. so i need to rename the file without the extension.
so the code should be,
if (file dont have mp3 or have no extension)
then rename.
how can i check that the file have no extension ?

thanks in advance for your answers.
 
Old 12-17-2008, 04:46 AM   #6
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
ls | grep -v "\.mp3$" | xargs -ifile mv file file.mp3
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rename reboot command coco03 Linux - General 6 04-19-2005 03:11 AM
rename command won't work Red Squirrel Linux - Newbie 4 03-03-2004 09:53 PM
Bulk image format conversions with a shell script? infidel Linux - Software 4 11-16-2003 08:20 PM
rename with command line shanenin Linux - Software 1 09-25-2003 08:03 PM
rename shell mikeshn Linux - General 5 09-21-2002 10:42 AM


All times are GMT -5. The time now is 06:07 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration