I have a list of file names abc1.doc, abc2.doc and so on. Always in the form text[number].doc. I want them renames to [number].text.doc.

How can I do this?


You can use prename (rename) perl script comes with perl package in Debian/Ubuntu. It is actually a fork of the original rename script. To solve your issue you can do:

rename -n 's/^([^[:digit:]]+)([^.]+)/$2\.$1/' *.doc 

-n is for dry-run, if you are satisfied with the changes remove -n.

Test :

$ rename -n 's/^([^[:digit:]]+)([^.]+)/$2\.$1/' *.doc 
abc10.doc renamed as 10.abc.doc
abc1.doc renamed as 1.abc.doc
abc2.doc renamed as 2.abc.doc
abc3.doc renamed as 3.abc.doc
abc4.doc renamed as 4.abc.doc
abc5.doc renamed as 5.abc.doc
abc6.doc renamed as 6.abc.doc
abc7.doc renamed as 7.abc.doc
abc8.doc renamed as 8.abc.doc
abc9.doc renamed as 9.abc.doc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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