Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
@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
@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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .