Skip to content

Instantly share code, notes, and snippets.

@jktravis
Created December 8, 2012 00:35
Show Gist options
  • Save jktravis/4237826 to your computer and use it in GitHub Desktop.
Save jktravis/4237826 to your computer and use it in GitHub Desktop.
Rename a group of files
#!/bin/bash
# Renames a group of files
counter=0
filename=$1
context=$2
ext=$3
if [ $# -ne 0 ]
then
if [ -z "${ext}" ]
then
ext=${context}
fi
for file in *.${context}
do
counter=$((counter+1))
mv "${file}" ${filename}_${counter}.${ext}
done
# echo "Filename: ${filename}, Context: ${context}, Ext: ${ext}"
else
echo "Usage: rename_files <base_file_name> <context> [extension]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment