#!/bin/bash -x x=1 y=1 #change this for jpg or other formats. $1 is the folder where the images are. given as an argument. for fname in $1/*.png do #for more than 999 files change to %04d if [ $y -le 4 ]; then rm $fname y=$(($y+1)) else mv $fname $1/`printf "%04d.png" $x` y=1 fi x=$(($x+1)) done