Bash Tip! Renaming files using Bash string operations

Bash Tip! Renaming files using Bash string operations

By : -

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.

Leave a Reply

Your email address will not be published.