Skip to content

Instantly share code, notes, and snippets.

@adam000
Forked from anonymous/move_sequential.bash
Last active December 20, 2015 08:19
Show Gist options
  • Save adam000/6099794 to your computer and use it in GitHub Desktop.
Save adam000/6099794 to your computer and use it in GitHub Desktop.
#!/bin/bash
function move_sequential {
if [[ $# != 4 ]]; then
echo Usage: move_sequential <prefix> <first number to move, inclusive> <last number to move, inclusive> <suffix>
return 1
fi
PREFIX=$1
FIRST=$2
LAST=$3
SUFFIX=$4
DIR="mv_$FIRST_$LAST"
mkdir $DIR
if [[ $? != 0 ]]; then
echo "Folder $DIR already exists :/"
return 2
fi
$IDX=1
for i in {$FIRST..$LAST}; do
NUM=`printf '%04d' $i`
NEWNUM=`printf '%04d' $IDX`
echo mv DSC_$NUM.JPG $DIR/DSC_$NEWNUM.JPG
$IDX=$(($IDX+1))
done
}
#untested, also an 'echo' instead of an actual mv for testing purposes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment