LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   renaming files (https://www.linuxquestions.org/questions/linux-software-2/renaming-files-496397/)

starwarsfan982 10-28-2006 12:23 PM

renaming files
 
I am trying to better organize my music collection. I have some files that have the name "01 - song.mp3". I want to rename them so that they are called just "song.mp3". Does anyone know how I can do this in bulk with a command line tool or program?

Thx, Starwarsfan982

matthewg42 10-28-2006 01:09 PM

1. Are your files all in one directory, or are they in directories?

1a. If they are in directories, do you wish to rename the directories too?

2. Do you want to remove spaces in filenames to make it more convenient to handle them in the shell?

3. Do you wish to remove characters which may cause problems on filesystems which have restrictions on which characters may be in filenames (e.g. remove : so that files can be transferred to FAT filesystems without freaking them out)?

4. Do you wish to rename files according to meta-data, e.g. ID3 tags?

matthewg42 10-28-2006 01:20 PM

OK, for a single directory, just removing leading numbers (e.g. track numbers on mp3 files)?

If so, the "rename" command which comes with perl is really good. You need to know about perl style regular expression to understand how it works, but the usage is easy when you do. e.g.

Code:

$ rename -v 's/^\d+\s*//' *.mp3
01 Public Service Announcer.mp3 renamed as Public Service Announcer.mp3
02 Watching Xanadu.mp3 renamed as Watching Xanadu.mp3
03 Instead.mp3 renamed as Instead.mp3
04 I Tried.mp3 renamed as I Tried.mp3
05 This Is Not Who We Were.mp3 renamed as This Is Not Who We Were.mp3
06 Barcode Bypass.mp3 renamed as Barcode Bypass.mp3
07 Only I.mp3 renamed as Only I.mp3
08 Animal Cannabus.mp3 renamed as Animal Cannabus.mp3
09 Strangeways Inside.mp3 renamed as Strangeways Inside.mp3
10 Mull Historical Society.mp3 renamed as Mull Historical Society.mp3
11 Paper Houses.mp3 renamed as Paper Houses.mp3

You can remove the -v option to prevent it spewing out all this verbose output.

You can add changing of spaces like this:

Code:

$ rename -v 's/^\d+\s*//; s/\s+/_/g;' *.mp3
You can add translation to lower case like this:

Code:

$ rename -v 's/^\d+\s*//; s/\s+/_/g; y/A-Z/a-z/' *.mp3
If you don't know about perl style regular expressions, this is probably total nonsense. They're very cool, so read the perlre(1) man page without delay!

fakie_flip 10-28-2006 02:42 PM

Hey, I wondered if there was a way to query a cddb database again for all of a music collection and use that info to rename all of the files. Amarok does a good job of getting the music information and song names. If possible, I'd like to use the information Amarok gets to rename all of my music. Thanks.

matthewg42 10-28-2006 03:30 PM

If you used CDDB when you backed up *cough* your music files from your CDs, the files should already contain the band, album and song titles in meta-data tags. In the case of MP3 files, these tags are called ID3 tags. This is typical behaviour for CD rippers which know about CDDB (i.e. most of them).

In this case, what you might be looking for is tagtool. If you're running Ubuntu, this is available in the Universe repository, and I'm sure it's available in other distros too.

Tagtool lets you rename files according to the contents of ID3 tags, and has a fairly nice GUI interface as well. Note that when you're renaming files which are already in directories and you want the new filenames to include new directory names, you should probably move them all to one directory first, else your new directory names will be "inside" the old directories. Work on a backup copy of your files first to make sure you know how it works.

fakie_flip 10-30-2006 12:42 PM

Quote:

Originally Posted by matthewg42
If you used CDDB when you backed up *cough* your music files from your CDs, the files should already contain the band, album and song titles in meta-data tags. In the case of MP3 files, these tags are called ID3 tags. This is typical behaviour for CD rippers which know about CDDB (i.e. most of them).

What about my music that is not mp3? Ogg vorbis does have tags. FLAC probably does not, but I am unsure about it. I have one album in FLAC, and probably more later. I wanted to ask you about the tags my mp3s should already have. They came from many sources. Could the tags be different? Should I re-tag them all using the same CDDB? Will a CDDB get queried again for the music that does not have tags?

Quote:

In this case, what you might be looking for is tagtool. If you're running Ubuntu, this is available in the Universe repository, and I'm sure it's available in other distros too.

Tagtool lets you rename files according to the contents of ID3 tags, and has a fairly nice GUI interface as well. Note that when you're renaming files which are already in directories and you want the new filenames to include new directory names, you should probably move them all to one directory first, else your new directory names will be "inside" the old directories. Work on a backup copy of
your files first to make sure you know how it works.
Nope, not Ubuntu. Read my info next to my name. I did find it with Apt in Debian Etch. I have a lot of software available to me. I thought the music had to be seperated to know which song is which when using the CDDB because it will take the lengths of each song to know what album it came from. Have you tried it? Thanks for telling me about it. You cleared up my confusion about tags and how mp3s get their names.

matthewg42 10-30-2006 01:00 PM

Quote:

Originally Posted by fakie_flip
FLAC probably does not, but I am unsure about it.

I don't know about FLAC.

Quote:

Originally Posted by fakie_flip
I wanted to ask you about the tags my mp3s should already have. They came from many sources. Could the tags be different? Should I re-tag them all using the same CDDB? Will a CDDB get queried again for the music that does not have tags?
...
I thought the music had to be seperated to know which song is which when using the CDDB because it will take the lengths of each song to know what album it came from. Have you tried it? Thanks for telling me about it. You cleared up my confusion about tags and how mp3s get their names.

I suppose you should make sure that all the tracks you want to rename have enough information for your naming scheme, e.g. if you're using the artist name, make sure all the files have this tag etc.

I don't know about re-tagging the files. The only tags I ever added were done at the time I was backing up from the CD, and in this case I believe the looking in the CDDB is done from information extracted from the CD's table of contents - I don't know if you can get the same info from the mp3/ogg/whatever files.

soggycornflake 10-30-2006 02:06 PM

You can add/replace tags on ogg/vorbis files with vorbiscomment (see -a, -t and -w options). Haven't come across any mp3 equivalent yet (though I'd imagine there's one around somewhere).


All times are GMT -5. The time now is 11:43 PM.