#! /bin/sh # Program to rename picture files with .jpg extensions sequentially # 2 command line parameters are allowed, the base name, and optionally a start # count # # procedure: # # 1) place yourself in the directory where your pictures are. # 2) type: picnamer fred 13 # # Picnamer will rename all *.jpg files fred_xxx.jpg # in your directory beginning with fred_013.jpg. # # If the second command line argument is missing, the count will # begin at 1. # # If the first command line argument is missing, the pictures will be # named px_xxx.jpg beginning at px_001.jpg # # The standard output produces a sed file to allow the pictures to be # renamed back to their original name. # ############################################################################### DATE=`date +%y%m%d` #If a parameter is given ($# >= 1), we accept it as the prefix if [ "$#" != "0" ]; then PREFIX=$1_ else PREFIX="px_" fi #If a second parameter is given, we assume it is a target prefix if [ $# -gt 1 ]; then LOOP=$2 else LOOP=1 fi echo "# jpgnamer's revert sed file" echo # Process the jpg or jpeg files for file in *.jpg do if [ "$file" != "*.jpg" ]; then if [ $LOOP -lt 10 ]; then file2=${PREFIX}00$LOOP.jpg else if [ $LOOP -lt 100 ]; then file2=${PREFIX}0$LOOP.jpg else file2=${PREFIX}$LOOP.jpg fi fi if [ -f $file2 ]; then # If file2 exists, copy it with date stamp cp "$file2" "$file2.$DATE" fi mv "$file" "$file2" # rename the file # Increment the counter LOOP=`expr $LOOP + 1` echo "s/$file2/$file/" fi done echo echo "# End of sedfile" exit 0