Good morning!
I'm studying shellscript and an exercise asks for a scan of files in the current directory and md5 hashes to be computed. It also asks that if there are identical files by comparing hashes, these files are printed. The code I was able to do gets the result, but it gets duplicated; I can not remove a file from the next scans once it has already been plotted as equal to another. Detail: You can not use redirection for temporary files.
#!/bin/bash
ifs=$IFS
IFS=$'\n'
echo "Verificando os hashes dos arquivos do diretório atual..."
for file1 in $(find . -maxdepth 1 -type f | cut -d "/" -f2); do
md51=$(md5sum $file1 | cut -d " " -f1)
for file2 in $(find . -maxdepth 1 -type f | cut -d "/" -f2 | grep -v "$file1"); do
md52=$(md5sum $file2 | cut -d " " -f1)
if [ "$md51" == "$md52" ]; then
echo "Arquivos $file1 e $file2 são iguais."
fi
done
done
I would also like to know if there is a more efficient way of doing this.
Thanks in advance for the help!