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

Possible Duplicate:
Batch rename files in Linux

I have a list of 1000 files in a directory in my linux system like this:

I want .en eliminated from all files, and rename them to:

Is there any bash, python, java or PHP script to do this?

share|improve this question

migrated from Nov 20 '12 at 12:00

This question came from our site for professional and enthusiast programmers.

marked as duplicate by BBlake, Oliver Salzburg Nov 20 '12 at 13:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

It should be easy with any one of the tools you mention. The question is... what have you tried? – psoft Nov 20 '12 at 11:53
up vote 1 down vote accepted

Just use this command :

rename 's/\.en\.srt$/.srt/' *.srt

rename is Perl rename, it's the default on Ubuntu :

$ LANG=C update-alternatives --display rename
rename - auto mode
  link currently points to /usr/bin/prename
/usr/bin/prename - priority 60
  slave rename.1.gz: /usr/share/man/man1/prename.1.gz
Current 'best' version is '/usr/bin/prename'.

It's installed with perl Ubuntu package itself.

share|improve this answer
This will remove the first instance of ".en.": "" will become "". If you want to remove only the final "en", you could do 's/\.en\.srt$/.srt/'. – Inductiveload Nov 20 '12 at 10:26
post editec accordingly – Gilles Quenot Nov 20 '12 at 10:30
@sputnick Thank you so much – user1838300 Nov 20 '12 at 10:55

The following command will do that:

find . -name '*' | sed 'h; s/$/.srt/; H; x; s/\n/ /' | xargs -l mv
  • find finds the files to be renamed
  • sed edits the filename
  • xargs calls the mv command for each filename to do the job

To check first what you are doing, try adding 'echo' just before mv, like this:

find . -name '*' | sed 'h; s/$/.srt/; H; x; s/\n/ /' | xargs -l echo mv
share|improve this answer

rename from util-linux should do that too:

rename .srt *
share|improve this answer

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