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
  mv ${file} ${file%%.html}.shtml

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

Leave a Reply

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