我正在尝试仅将原始文件从一个目录复制到另一个目录,但某些文件具有相同的名称...我正在尝试使用哈希来比较文件,如果它不在目录中,则将其发送到那里并且名称是否相同它到file_name.something。此时我得到一些文件,并且具有相同名称的文件被覆盖......有人可以提出一些建议吗?
#!/bin/bash -xv
source_folder=$1
destination_folder=$2
if [ $# -eq 0 ]
then
echo "usage:$0 directory_name";exit 999;
fi
if [ -d $source_folder ]
then
echo "source source_folder exists."
else
echo "Source folder doesn't exist"
exit 1;
fi
if [ -d $destination_folder ]
then
echo "Destination folder exists"
else
mkdir $destination_folder
fi
find "$source_folder" -name "IMG_[0-9][0-9][0-9][0-9].JPG" -exec ./check {} $destination_folder/ \;
#!/bin/bash -xv
file=$1
destination_folder=$2
file_hash=`md5sum "$file" | cut -d ' ' -f 1`
for a in $destination_folder/*
do
curr_hash=$(md5sum "$a" | cut -d ' ' -f 1)
curr_file=$a
if [ ! "$file_hash" == "$curr_hash" ];
then
if [[ -f $destination_folder/$file ]] ;
then # CAN ANYBODY TELL ME WHY IT IGNORES THIS LINE
cp "$file" "$file.JPG"
mv "$file.JPG" "$destintion_folder"
else # IT GOES STRAIGHT FOR THIS ONE
cp "$file" "$destination_folder"
fi
fi
done