0

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?

Edit

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.

1 Answers1

0

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:

ELF

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.

Glorfindel
  • 815
  • 2
  • 10
  • 19