Skip to content

Instantly share code, notes, and snippets.

@adrianorsouza
Created May 5, 2015 17:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save adrianorsouza/77a95974034827f80ade to your computer and use it in GitHub Desktop.
Rename list of files within a given directory
#!/bin/bash
# @autor: Adriano Rosa <http://adrianorosa.com>
# @file: renames.sh
# @description: basic file renamer
# @usage: ./renames.sh path/ .html .php
criteria=$1
re_match=$2
replace=$3
if [[ $criteria && $re_match && $replace ]]; then
for i in $( ls *$criteria* );
do
src=$i
tgt=$(echo $i | sed -e "s/$re_match/$replace/")
mv $src $tgt
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment