Thursday 22 March 2012

Rename multiple files using one command

On Redhat Linux machine, suppose we have hundreds of .txt files, if want want to rename them to .sh file, there are a few ways to do:

1. use rename command
rename txt sh *.txt

2. write script
for f in *.txt; do mv $f ${f/.txt/.sh}; done

${f/.txt/.sh} is string replacement in bash, for details, please see string manipulation in bash

No comments:

Post a Comment