Bash는 온라인 파일의 MD5를 얻습니다.

Bash는 온라인 파일의 MD5를 얻습니다.

온라인 파일의 MD5 해시를 가져온 다음 이를 로컬 컴퓨터에 있는 파일과 비교해야 합니다.

Bash에서 어떻게 할 수 있나요?

답변1

curl다음을 사용하여 온라인 파일을 가져올 수 있습니다.

curl -sL http://www.your.fi/le | md5sum | cut -d ' ' -f 1

다른 것과 비교하려면 변수에 저장한 후 다음을 진행하세요.

online_md5="$(curl -sL http://www.your.fi/le | md5sum | cut -d ' ' -f 1)"
local_md5="$(md5sum "$file" | cut -d ' ' -f 1)"

if [ "$online_md5" = "$local_md5" ]; then
    echo "hurray, they are equal!"
fi

답변2

wget를 사용하여 표준 출력으로 다운로드할 수 있습니다 -O-.

 wget http://example.com/some-file.html -O- \
     | md5sum \
     | cut -f1 -d' ' \
     | diff - <(md5sum local-file.html | cut -f1 -d' ')

md5sumMD5 뒤에 파일 이름을 추가하면 cut.

답변3

 wget -q -O- http://example.com/your_file | md5sum | sed 's:-$:local_file:' | md5sum -c

http://example.com/your_file온라인 파일의 URL과 local_file로컬 파일의 이름 으로 바꾸세요 .

답변4

Via wgetand md5sumand awk긴 단일 라이너로=)

awk 'FNR == NR {a[0]=$1; next} {if (a[0]==$1) {print "match"; exit} {print "no match"}}'\
 <(wget -O- -q URL | md5sum)\
 <(md5sum local_file)

$ awk 'FNR == NR {a[0]=$1; next} {if (a[0]==$1) {print "match"; exit} {print "no match"}}' <(wget -O- -q http://security.ubuntu.com/ubuntu/pool/main/h/hunspell/libhunspell-1.2-0_1.2.8-6ubuntu1_i386.deb | md5sum) <(md5sum libhunspell-1.2-0_1.2.8-6ubuntu1_i386.deb)
match

$ awk 'FNR == NR {a[0]=$1; next} {if (a[0]==$1) {print "match"; exit} {print "no match"}}' <(wget -O- -q http://security.ubuntu.com/ubuntu/pool/main/h/hunspell/libhunspell-1.2-0_1.2.8-6ubuntu1_i386.deb | md5sum) <(md5sum foo) 
no match

관련 정보