Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

i'm embarrassed i even have to ask but I have a directory with m4a files that have the number of the track from the cd appended to the beginning of the filename, such as this:

1-01 Smash.m4a

how can I remove the "1-01 " using rename? or any other linux command for that matter. If it makes a difference, i'm on fedora-13.

EDIT (bonus points if you can explain why this doesn't work) just as a test, i tried this:

rename 1-0?? SSS *.m4a

without any changes made to any of the filenames in the directory

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Give this a whirl (in the directory with the files you want to rename):-

for i in *; do mv -v "$i" "$(echo "$i" | cut -f2- -d ' ')"; done
share|improve this answer
    
well, i don't know what this is (perl?) but it worked on all but one filename. to be fair, it is the special case in the directory: 1-04 Bass Suite #1.m4a ...the problem is, i'm still no more knowledgeable about rename. Is this not doable with rename? –  Ramy Dec 19 '10 at 1:10
    
It's just shell... so you should be able to run that straight from the commandline. I'd imagine it is doable with rename, but I've not used it much myself. –  Andy Smith Dec 19 '10 at 1:12
    
rename 's/^\d+-\d+\s//g' *.m4a should do the trick, though! –  Andy Smith Dec 19 '10 at 1:14
3  
@Ramy, @Andy: On Debian, rename is actually prename, a Perl script that uses regexes. On other systems, rename is a much simpler utility (from util-linux-ng, IIRC) which only accepts fixed "from" and "to" strings. –  grawity Dec 19 '10 at 12:25
3  
@Michael: Process creation costs a lot more on WinNT than it does on most Unix-like OSes. (This is why threads are more common on Windows than fork() is.) –  grawity Dec 19 '10 at 12:28
show 12 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.