I am using a find command to find files formatted 'DGT_????.JPG'. I would like to then copy these to another folder. However, the script finds duplicate filenames and I am trying to find a way to append the files in the source directory being copied with an extra '.JPG' on the end of the filename instead of overwriting the file in the target directory. So for example if 'DGT_0001' was in both folders, the filename of the one in the source directory would be appended to 'DGT_0001.JPG.JPG', then moved to the target directory.
My code is below
#!/bin/sh
clear
SRC="$1"
DEST="$2"
SUFFIX=.JPG
if [ "$#" -eq 0 ]; then
echo "two arguments required"
fi
if [ ! -d "$SRC" ]; then
echo "Source directory does not exist"
exit
fi
if [ ! -d "$DEST" ]; then
mkdir "$2"
fi
for image in $(find "$SRC" -type f -iname IMG_[0-9][0-9][0-9][0-9].JPG)
do
cp "$image" "$DEST"
done
You can have
cp
make the backup:From
man cp
: