Created
December 8, 2012 00:35
-
-
Save jktravis/4237826 to your computer and use it in GitHub Desktop.
Rename a group of files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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