Thursday, December 4th, 2008...8:45 pm
Linux/Unix rename multiple files trick
All credit for this wonderful trick belongs to my co-worker Adam.
If you need to replace a common string in multiple files to another common string, you can use the rename command.
rename _from_ _to_ filename
so rename a b a*.log
would change a1.log to b1.log and a2.log to b2.log
further, if you want to remove that common string, you can type the following
rename _from_ '' filename
so rename a '' a*.log
would change a1.log to 1.log and a2.log to 2.log
The best example came when we were cloning a database and the dbf files had the oracle sid in the name.
rename prod_ test_ prod_*.dbf
this changed
prod_system01.dbf to test_system01.dbf
prod_users01.dbf to test_users01.dbf
prod_sysaux01.dbf to test_sysaux01.dbf
… and so on.
Leave a Reply