常常在Linux下下載軟件的人,必定會有一個良好的習慣:校驗文件的hash,以肯定文件的完整性甚至是安全性。我配置環境的時候也剛好用到了,筆者的是一個lubuntu的機子。這裏我大體作個記錄。(不瞭解hash的請自行查閱相關資料)html
MD5校驗:ubuntu
magic@luna:~/lnmp$ md5sum lnmp1.3-full.tar.gz a5aa55cd177cd9b9176ad697c12e45c0 lnmp1.3-full.tar.gz
或者咱們能夠保存到一個文件中:安全
magic@luna:~/lnmp$ md5sum lnmp1.3-full.tar.gz > md5-hash.txt
而後:bash
magic@luna:~/lnmp$ cat md5-hash.txt a5aa55cd177cd9b9176ad697c12e45c0 lnmp1.3-full.tar.gz
還能夠根據已經獲得的hash來確認文件:ui
magic@luna:~/lnmp$ md5sum -c md5-hash.txt lnmp1.3-full.tar.gz: 肯定 magic@luna:~/lnmp$
SHA1:this
這個相似於MD5校驗方法:spa
magic@luna:~/lnmp$ sha1sum lnmp1.3-full.tar.gz ee7ec6e8be0b3b5a481df903427261236f9bb057 lnmp1.3-full.tar.gz
或者保存到文件中再去查看:翻譯
magic@luna:~/lnmp$ sha1sum lnmp1.3-full.tar.gz > sha1-hash.txt magic@luna:~/lnmp$ cat sha1-hash.txt ee7ec6e8be0b3b5a481df903427261236f9bb057 lnmp1.3-full.tar.gz
已知hash狀況下的校驗(一般這個狀況還挺多):code
magic@luna:~/lnmp$ sha1sum -c sha1-hash.txt lnmp1.3-full.tar.gz: 肯定 magic@luna:~/lnmp$
注意事項:在已知hash數值狀況下對文件進行校驗的時候要注意,必定要讓系統可以找到要校驗的文件。不然就無法進行校驗了。具體的使用說明,能夠經過md5(sha1)sum --help來查看:orm
magic@luna:~/lnmp$ sha1sum --help Usage: sha1sum [OPTION]... [FILE]... Print or check SHA1 (160-bit) checksums. 若是沒有指定文件,或者文件爲"-",則從標準輸入讀取。 -b, --binary read in binary mode -c, --check 從文件中讀取SHA1 的校驗值並予以檢查 --tag create a BSD-style checksum -t, --text 以純文本模式讀取(默認) The following five options are useful only when verifying checksums: --ignore-missing don't fail or report status for missing files --quiet don't print OK for each successfully verified file --status don't output anything, status code shows success --strict exit non-zero for improperly formatted checksum lines -w, --warn warn about improperly formatted checksum lines --help 顯示此幫助信息並退出 --version 顯示版本信息並退出 The sums are computed as described in FIPS-180-1. When checking, the input should be a former output of this program. The default mode is to print a line with checksum, a space, a character indicating input mode ('*' for binary, ' ' for text or where binary is insignificant), and name for each FILE. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> 請向<http://translationproject.org/team/zh_CN.html> 報告sha1sum 的翻譯錯誤 Full documentation at: <http://www.gnu.org/software/coreutils/sha1sum> or available locally via: info '(coreutils) sha1sum invocation'
ps:轉載請註明文章出處。