Bash Tip! Renaming files using Bash string operations

To rename all html files in a particular directory to shtml files, use the following loop:

for file in *.html
do
  mv ${file} ${file%%.html}.shtml
done

This uses the ${variable%%match} format which strips the longest match from the end of the variable.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *