2
Good morning!
I am studying shellscript and an exercise asks for a scan of files in the current directory and to calculate the md5 hashes. It also asks that, in case there are identical files by comparing the hashes, these files be printed. The code I was able to do achieves the result, but it is duplicated; I cannot remove a file from the next scans once it has already been plotted as equal to another. Detail: cannot use redirect to 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 task.
Thanks in advance for your help!