This question already has an answer here:

I have around 5000 .xml files in my unix directory. I want to add extension Hist to all the file names before .xml extension. For example if the file is ABCD.xml, I want to rename it to ABCDHist.xml. And I want to do this for all the 5000 files in my directory. Is there a one line command to do that?


I am doing this on a unix (aix) box and tool that I am using is attachmate reflection ssh client. Does not look like perl commands are executable there.

marked as duplicate by G-Man, X Tian, drewbenn, Romeo Ninov, Kiwy Mar 13 '18 at 8:18

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.


Using perl's rename :

rename -n 's/\.xml$/Hist.xml/' *.xml

(remove -n switch when your tests are OK)

warning There are other tools with the same name which may or may not be able to do this, so be careful.

If you run the following command (GNU)

$ file "$(readlink -f "$(type -p rename)")"

and you have a result like

.../rename: Perl script, ASCII text executable

and not containing:


then this seems to be the right tool =)

If not, to make it the default (usually already the case) on Debian and derivative like Ubuntu :

$ sudo update-alternatives --set rename /path/to/rename

(replace /path/to/rename to the path of your perl's rename command.

If you don't have this command, search your package manager to install it or do it manually

Last but not least, this tool was originally written by Larry Wall, the Perl's dad.

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