LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-16-2010, 09:43 PM   #1
valkarin
Member
 
Registered: Dec 2006
Distribution: Ubuntu
Posts: 41

Rep: Reputation: 15
Need to delete prefix from files


I have a lot of mp3 files that have the track number as a prefix toi the file name.

Ex. 01_this_file.mp3

They are in ascending order and I would like to get rid of the track number sot that it reads:

this_file.mp3

There are about 200 files so I would like to find a way to rename them all at once if possible. Any suggestions?

Last edited by valkarin; 07-16-2010 at 09:44 PM. Reason: Unclear psot
 
Old 07-16-2010, 10:15 PM   #2
allanf
Member
 
Registered: Sep 2008
Location: MN
Distribution: Gentoo, Fedora, Suse, Slackware, Debian, CentOS
Posts: 100
Blog Entries: 1

Rep: Reputation: 20
NOTE: THIS IS FIXED BELOW as this was attempting to remove "digit_digit_digit_..." rather than "digitdigitdigit..._".

safe code before the real script

Code:
for f in $(ls [0-9][0-9]*); do echo mv "${f}" "${f##[0-9]_}"; done
The real code
Code:
for f in $(ls [0-9][0-9]*); do mv "${f}" "${f##[0-9]_}"; done

Last edited by allanf; 07-18-2010 at 02:56 PM.
 
Old 07-17-2010, 06:14 AM   #3
valkarin
Member
 
Registered: Dec 2006
Distribution: Ubuntu
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks for the reply. It didn't work. Got this error message:

mv: `01_this_file.mp3' and `01_this_file.mp3' are the same file. Any other ideas?
 
Old 07-17-2010, 06:27 AM   #4
valkarin
Member
 
Registered: Dec 2006
Distribution: Ubuntu
Posts: 41

Original Poster
Rep: Reputation: 15
Found a program that did it for me. Krename.
 
Old 07-18-2010, 02:54 PM   #5
allanf
Member
 
Registered: Sep 2008
Location: MN
Distribution: Gentoo, Fedora, Suse, Slackware, Debian, CentOS
Posts: 100
Blog Entries: 1

Rep: Reputation: 20
Quote:
Originally Posted by allanf View Post
safe code before the real script

Code:
for f in $(ls [0-9][0-9]*); do echo mv "${f}" "${f##[0-9]_}"; done
The real code
Code:
for f in $(ls [0-9][0-9]*); do mv "${f}" "${f##[0-9]_}"; done
This should have been:

Code:
for f in $(ls [0-9][0-9]*); do echo mv "${f}" "${f#[0-9]*_}"; done
The real code
Code:
for f in $(ls [0-9][0-9]*); do mv "${f}" "${f#[0-9]*_}"; done
[/QUOTE]

The problem in the original is it attempted to remove digit_digit_... rather than digitdigit..._


Here is a sample test case to show it working:
Code:
bash$ for f in {0,1,2,3}{0,1,2,3,4,5,6,7,8,9}; do touch ${f}_this_file_${f}.mp3; done
bash$ lsc
00_this_file_00.mp3  08_this_file_08.mp3  16_this_file_16.mp3  24_this_file_24.mp3  32_this_file_32.mp3
01_this_file_01.mp3  09_this_file_09.mp3  17_this_file_17.mp3  25_this_file_25.mp3  33_this_file_33.mp3
02_this_file_02.mp3  10_this_file_10.mp3  18_this_file_18.mp3  26_this_file_26.mp3  34_this_file_34.mp3
03_this_file_03.mp3  11_this_file_11.mp3  19_this_file_19.mp3  27_this_file_27.mp3  35_this_file_35.mp3
04_this_file_04.mp3  12_this_file_12.mp3  20_this_file_20.mp3  28_this_file_28.mp3  36_this_file_36.mp3
05_this_file_05.mp3  13_this_file_13.mp3  21_this_file_21.mp3  29_this_file_29.mp3  37_this_file_37.mp3
06_this_file_06.mp3  14_this_file_14.mp3  22_this_file_22.mp3  30_this_file_30.mp3  38_this_file_38.mp3
07_this_file_07.mp3  15_this_file_15.mp3  23_this_file_23.mp3  31_this_file_31.mp3  39_this_file_39.mp3
bash$ for f in $(ls [0-9][0-9]*); do mv "${f}" "${f#[0-9]*_}"; done
bash$ lsc
this_file_00.mp3  this_file_07.mp3  this_file_14.mp3  this_file_21.mp3  this_file_28.mp3  this_file_35.mp3
this_file_01.mp3  this_file_08.mp3  this_file_15.mp3  this_file_22.mp3  this_file_29.mp3  this_file_36.mp3
this_file_02.mp3  this_file_09.mp3  this_file_16.mp3  this_file_23.mp3  this_file_30.mp3  this_file_37.mp3
this_file_03.mp3  this_file_10.mp3  this_file_17.mp3  this_file_24.mp3  this_file_31.mp3  this_file_38.mp3
this_file_04.mp3  this_file_11.mp3  this_file_18.mp3  this_file_25.mp3  this_file_32.mp3  this_file_39.mp3
this_file_05.mp3  this_file_12.mp3  this_file_19.mp3  this_file_26.mp3  this_file_33.mp3
this_file_06.mp3  this_file_13.mp3  this_file_20.mp3  this_file_27.mp3  this_file_34.mp3
bash$
 
  


Reply



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
Can I delete files in /mnt/tmp? and Files in the trash can will not delete? M$ISBS Slackware 15 10-02-2009 11:56 PM
Copy files which doesn not start with some prefix? laki47 Linux - Newbie 2 07-09-2009 03:31 PM
difference b/w AF_ prefix and PF_ prefix related to socket Ashok_mittal Linux - Newbie 1 03-20-2008 04:15 PM
Rename files and add prefix SevenMedia Linux - Newbie 6 01-16-2008 07:04 AM
How can I change the prefix of multiple files in a directory 6millionbucks Programming 13 08-01-2007 11:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:16 AM.

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