LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Newbie
User Name
Password
Linux - Newbie This 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
 
Thread Tools
Old 12-16-2008, 05:51 AM   #1
ashrafulkarim
LQ Newbie
 
Registered: Nov 2008
Posts: 5
Thanked: 0
shell command for bulk 'rename'


[Log in to get rid of this advertisement]
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
ashrafulkarim is offline     Reply With Quote
Old 12-16-2008, 06:07 AM   #2
sycamorex
Senior Member
 
Registered: Nov 2005
Location: London
Distribution: Slackware 13 32/64
Posts: 1,654
Thanked: 75
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
sycamorex is offline     Reply With Quote
Thanked by:
Old 12-16-2008, 06:14 AM   #3
colucix
Guru
 
Registered: Sep 2003
Location: Bologna, Italia
Distribution: OpenSUSE 11.1 CentOS 5.4 VectorLinux 6.0
Posts: 5,129
Thanked: 464
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..
colucix is offline     Reply With Quote
Thanked by:
Old 12-16-2008, 06:16 AM   #4
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,404
Thanked: 34
ls | xargs -ifile mv file file.mp3
Agrouf is offline     Reply With Quote
Thanked by:
Old 12-17-2008, 04:44 AM   #5
ashrafulkarim
LQ Newbie
 
Registered: Nov 2008
Posts: 5
Thanked: 0

Original Poster
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.
ashrafulkarim is offline     Reply With Quote
Old 12-17-2008, 04:46 AM   #6
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,404
Thanked: 34
ls | grep -v "\.mp3$" | xargs -ifile mv file file.mp3
Agrouf is offline     Reply With Quote
Thanked by:

Reply

Bookmarks


Thread Tools

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 04:54 AM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration