LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-09-2014, 03:04 PM   #1
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,935

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
Question Batch rename to remove special characters from files.


Hi.

I move MP3 files from my Linux Mint MATE PC using the Caja file manager to my Android phone from time to time. Sometimes the files contain a question mark or double quotes or a colon, etc. How can I batch rename all the mp3 files to remove all special characters?

Would the rename command be feasible? Or is there a GUI program to do this?

Thanks.
 
Old 01-09-2014, 08:32 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
This is rather crude, but it works for me.

Code:
for f in *.mp3 *.flac; do
    mv "$f" `echo $f | tr -cd "a-zA-Z0-9\-_\ \." | sed s/' - '/'-'/g | sed s/' '/_/g | sed s/__/_/g | sed s/'('//g | sed s/')'//g`
done
Save the code to a file. Make the file executable (chmod ugo+x) and run the file in the directory with the music files.

jlinkels
 
1 members found this post helpful.
Old 01-10-2014, 09:56 AM   #3
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,935

Original Poster
Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
Thumbs up

Cheers jlinkels. Your solution worked perfectly.
 
Old 01-13-2014, 02:27 PM   #4
linustalman
LQ Guru
 
Registered: Mar 2010
Location: Ireland
Distribution: Debian 12 Bookworm
Posts: 5,935

Original Poster
Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
Thumbs up

A further tweak to your excellent code.

Code:
for f in *.flac *.mp3 *.oga *.ogg *.wav; do
 
  


Reply

Tags
batch, characters, files, rename, special


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Rename filenames contain special characters (/) senthilvael Linux - Server 6 08-27-2013 05:28 AM
Rename all files in dir to remove first nine characters zappadragon Linux - Newbie 4 11-13-2011 06:00 AM
[SOLVED] Remove special characters from a string ajeesh.tr Programming 2 01-31-2011 12:12 AM
How to remove file with name containing only special characters abhisheknayak Linux - Newbie 5 07-04-2008 10:53 AM
How to rename file while copying - and remove special characters corporal79 Linux - General 3 10-11-2007 04:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:04 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
Open Source Consulting | Domain Registration