Replacing characters in multiple file names
by Zubair on May.05, 2010, under Technology, Unix programming
I had a large set of shell scripts each of which i needed to run on separate planetLab nodes for which I included the name of the vantage point in every file. I had a pre-string to every file name which i then needed to replace. Unix/Linux makes this things so much more easier in this case.
Original name of file(s): tcpTrace-[vantageName-1].sh
I needed to change the inital string name from tcpTrace to pingTrace: Final name of file(s): pingTrace-[vantageName-1].sh
Since there was over 250 such files in my directory – a manual rename would be really tedious. I wrote the following rather simple shell script to do the job:
#!/bin/bashfor file in tcpTrace*.shdomv $file pingTrace${file#tcpTrace}done