bash script to rename in mass


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script to rename in mass
# 1  
Old 09-26-2008
bash script to rename in mass

Basically, I have a huge amount of files (ripped audiobooks) that all have the same garbage in their filenames. I'm wondering how to go about writing a bash script to mass rename them. Example filenames as they stand now:

Code:
The First CD - 1x01 - Title 1.mp3
The First CD - 1x02 - Title 2.mp3
The First CD - 1x03 - Title 3.mp3
The First CD - 1x04 - Title 4.mp3

I'd like to have the script ask me what needs to be removed and then do it.

In this case, I want to remove the text: "The First CD - "
The output of the directory above would then be:

Code:
1x01 - Title 1.mp3
1x02 - Title 2.mp3
1x03 - Title 3.mp3
1x04 - Title 4.mp3

Thanks all!
# 2  
Old 09-26-2008
Code:
for i in *.mp3
do 
   echo mv "$i" "${i/The First CD - /}"
done

If that's what you want, just remove the echo
# 3  
Old 09-26-2008
If you have rename:

Code:
rename 'The First CD - ' '' *.mp3

# 4  
Old 09-26-2008
Killer! Thanks for the suggestions guys. I found rename.pl from this site.
# 5  
Old 09-26-2008
if you have Python , you can use this script.
eg usage
Code:
# ls -1 *Title*mp3
The First CD - 1x01 - Title 1.mp3
The First CD - 1x02 - Title 2.mp3

# filerenamer.py -p "The First CD - " -e "" -l "*Title*mp3" #use -l to check
==>>>>  [ /home/The First CD - 1x01 - Title 1.mp3 ]==>[ /home/1x01 - Title 1.mp3 ]
==>>>>  [ /home/The First CD - 1x02 - Title 2.mp3 ]==>[ /home/1x02 - Title 2.mp3 ]

# filerenamer.py -p "The First CD - " -e ""  "*Title*mp3" #remove -l to commit
/home/The First CD - 1x01 - Title 1.mp3  is renamed to  /home/1x01 - Title 1.mp3
/home/The First CD - 1x02 - Title 2.mp3  is renamed to  /home/1x02 - Title 2.mp3

# ls -1 *Title*mp3
1x01 - Title 1.mp3
1x02 - Title 2.mp3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

2. Shell Programming and Scripting

Rename mass files with text from first line

I have a few hundred text files that are currently numbered files. I would like to rename each one with the text from the first line in the file. I would prefer this is perl script rather than a one liner as it wil be after many alterations to the file via an existing script. Any help would be... (1 Reply)
Discussion started by: GWhizz
1 Replies

3. UNIX for Dummies Questions & Answers

Bash script to execute a program to rename files

I just can't figure it out , so please just give me a pice of advise how to: The existing Linux program foo2bar takes as its only argument the name of a single foo file and converts it to an appropriately-named bar file. Provide a script that when executed will run foo2bar against all foo... (4 Replies)
Discussion started by: raymen
4 Replies

4. UNIX for Dummies Questions & Answers

Bash script to rename files in a directory

Dear friends, I have created a script to rename all files in a directory by appending the file name with username (who created the file), the date it was created. For example, "apple.doc" should be renamed to "johnFeb23apple.doc" where "john" is the owner and "Feb23" is file created date. It... (4 Replies)
Discussion started by: djsnifer
4 Replies

5. UNIX for Dummies Questions & Answers

Bash script to rename all files within a folder...

Hi. I don't have any experience with making scripts in bash. I need a simple script to rename all files in a folder to the format file1.avi, file2.avi, file3.avi, and so on..... Please note that the original files have different filenames and different extensions. But they all need to be... (2 Replies)
Discussion started by: dranzer
2 Replies

6. UNIX for Dummies Questions & Answers

Need help to mass rename files

Hi. I've got 75 mp3s that have the word 'Émission' in their filename. They are all in this format: Émission bla1 bla1.mp3 Émission bla2 bla2.mp3 Émission bla3 bla3.mp3 etc... I would just like to mass replace 'Émission' by 'Emission'; basically replace 'É' with 'E'. The rest of the... (10 Replies)
Discussion started by: Kingzy
10 Replies

7. Shell Programming and Scripting

bash script to rename multiple directories

Hello I have a directory structure with year in format 4 digits, e.g 2009, below which is month format 1 or 2 digits, e.g 1 or 12, blow which is day format 1 or 2 digits, e.g 1 or 31. I want to change the names of lots of directories to the be Year - 4 digits , e.g 2009 - No change here... (4 Replies)
Discussion started by: garethsays
4 Replies

8. Shell Programming and Scripting

Hello - new here - bash script - need to rename and zip files.

I'm working on a project that basically unzips three zip files. When these unzip they create about 70+ directories with subdirectories of year/month with about 3 to 9 pdf files in each directory. Basically, I'm needing to figure out a way to zip these pdf files up. for instance the script... (1 Reply)
Discussion started by: Aixia
1 Replies

9. UNIX for Dummies Questions & Answers

Mass Copy/rename

Don't tell me DOS can do something UNIX can't do! I want to copy a number of files from one directory to another, and at the same time change the names. The name changes would be common, e.g., all files starting with the letter 'L' and ending in '30.NEW554', with the copied or new files also... (6 Replies)
Discussion started by: lwilsonFG
6 Replies

10. UNIX for Dummies Questions & Answers

Easy way to mass rename files?

Hi. What is the easiest way to rename a bunch of files? For example taking all files ending in ".php3" and rename them to end in ".php" I could write a script to do this, but there is probably an easier way... Thanks! (17 Replies)
Discussion started by: Thermopylae
17 Replies
Login or Register to Ask a Question