Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 want to rename the below files, such that the first 4 chars and last 7 chars are removed, the remaining chars to be converted to decimal, while rename.

Example if the filename is 0030002345678.txt, should be renamed to 00.txt(removing the chars and converting to hex).

If it is 00300A2345678.txt, should be renamed to 10.txt(after conversion from hex of '0A'

share|improve this question
up vote 1 down vote accepted

What about this:

ls | python -c 'import sys, os; print len([os.system("mv %s %02i.%s" % (name[:-1], int(name.split(".")[0][4:-7], 16), name.split(".")[1])) for name in sys.stdin])'

Assumes the files to be renamed are exactly those that ls would print; supply anything more relevant, if this is not the case.

share|improve this answer

Your Answer


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.