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 08-15-2014, 09:59 PM   #1
e1e_
LQ Newbie
 
Registered: Aug 2014
Posts: 4

Rep: Reputation: Disabled
renaming multiple files


Is there a way to rename multiple files that all have the same extension. I'd like to remove most of the first part of the file name, leaving the rest the same.

e.g (01) albumtitle_trackname.mp3, (02) albumtitle_trackname.mp3 etc.

I want to remove the '(01) albumtitle_' part, keeping each individual trackname.mp3 the same.
 
Old 08-15-2014, 11:26 PM   #2
notKlaatu
Member
 
Registered: Sep 2010
Location: Wellington, New Zealand
Distribution: Slackware
Posts: 461

Rep: Reputation: 123Reputation: 123
Assuming you are using BASH, (you probably are), then you can create a 'for' loop to cycle through all mp3 files in the current directory and rename them:

Code:
for i in *mp3; do mv $i $(echo $i | cut -f2 -d"_") ; done
I would make a copy of the folder containing these tracks, or just make a new folder that contains a copy of ONE of the tracks, and test it first, just to make sure it does what you want.
 
Old 08-15-2014, 11:58 PM   #3
e1e_
LQ Newbie
 
Registered: Aug 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks for the reply.

This is exactly how the tracks look (the brackets and spaces are actually part of the file names)

(01) [album name] foo.flac

When i do
Code:
for i in *flac; do mv $i $(echo $i | cut -f2 -d"_") ; done
i get
Code:
mv: target ‘track1.flac’ is not a directory
mv: target ‘track2.flac’ is not a directory
etc.

also, does *flac need to be *.flac?

I have been reading the man page for mmv all morning and i can't work it out. Your way seems more fun though, heh...
 
Old 08-16-2014, 12:04 AM   #4
pwalden
Member
 
Registered: Jun 2003
Location: Washington
Distribution: Fedora FC19, Raspbian
Posts: 295

Rep: Reputation: 38
Another alternative if you are dealing with mp3 files is that most mp3 tag applications support mass file renaming based on tag values.

easytag is the application I use.
 
Old 08-16-2014, 12:23 AM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 659

Rep: Reputation: 160Reputation: 160
Had you RTFM'd for "cut" - including what is the definition and applicabilty for a LIST or range, you could perhaps have easily constructed the correct syntax.

For instance see:
See http://linux.die.net/man/1/cut

OK
 
Old 08-16-2014, 12:32 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,504

Rep: Reputation: 1079Reputation: 1079Reputation: 1079Reputation: 1079Reputation: 1079Reputation: 1079Reputation: 1079Reputation: 1079
The blank character(s) is the problem - use (double) quotes.
Shelling out for 2 extra programs is unnecessary - bash can handle this. Presuming there is a "_" as last unwanted character, try this
Code:
for i in *flac; do mv "$i" ${i##*_} ; done
 
Old 08-16-2014, 01:02 AM   #7
e1e_
LQ Newbie
 
Registered: Aug 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
The blank character(s) is the problem - use (double) quotes.
Shelling out for 2 extra programs is unnecessary - bash can handle this. Presuming there is a "_" as last unwanted character, try this
Code:
for i in *flac; do mv "$i" ${i##*_} ; done
The unwanted part of the file names is everything before 'track one.flac'. The stuff inside the brackets.
Quote:
(01) [album name] track one.flac
I get the same error when i run your code too.

Code:
mv: target ‘one.flac’ is not a directory
mv: target ‘two.flac’ is not a directory
and it also removes the first word of the part of the file name that I want to keep. It removed 'track' from 'track one.flac' so I got 'one.flac is not a directory'
 
Old 08-17-2014, 03:31 AM   #8
notKlaatu
Member
 
Registered: Sep 2010
Location: Wellington, New Zealand
Distribution: Slackware
Posts: 461

Rep: Reputation: 123Reputation: 123
This would have worked, based on the original filename you mentioned (one delimited by underscores), it was just missing double quotes:

Code:
for i in *flac; do mv "$i" "${i##*_}" ; done
However...

The answer is highly highly dependent upon what exactly your file names are.

If we don't know the characters to parse, we cannot give you an exact command and you will have to adjust what we are telling you to fit the actual filenames.

I am going to assume that a filename is exactly this:

(01) [album name] track one.flac

Based on that, you can do this command:
Code:
for i in *flac ; do mv "$i" "$(echo "$i" | cut -f4- -d" ")" ; done
If your files are not named that (and they probably aren't, because probably your album name isn't really just [album name]) then you need to adjust the 'cut' portion of that command, or else it will "cut" at the wrong point in your filename. Currently it is set to count 4 fields, delimited by spaces (" "). So if you album name is not [album name] then it won't work.

Give us an exact dump of the folder that you want, and we can give you the literal command you can type in. Otherwise, you're probably going to have to change it to suit your requirements.

Another option, in the GUI, is the XFCE file manager Thunar. It has a bulk rename function that might make this easier.
 
  


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
renaming multiple files linuxhippy Slackware 10 01-21-2011 02:53 AM
Renaming Multiple files Viablade Linux - Newbie 1 02-11-2009 02:47 PM
Renaming multiple files Changes Linux - Newbie 1 02-01-2009 10:58 PM
renaming multiple files yanchina12 Linux - Newbie 5 12-21-2007 08:56 AM
Renaming multiple files ajcns Linux - Newbie 2 01-20-2007 12:04 AM


All times are GMT -5. The time now is 09:31 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration