Linux md5sum 的用法
生活随笔
收集整理的這篇文章主要介紹了
Linux md5sum 的用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
MD5 算法常常被用來驗證網絡文件傳輸的完整性,防止文件被篡改。MD5 全稱是報文摘要算法,此算法對任意長度
的信息逐位計算,產生一個二進制長度為 128 位(十六進制長度 32 位)的報文摘要,不同的文件產生相同的報文摘要的可
能性非常小。
在 Linux 上,md5sum 是用來計算和校驗文件報文摘要的工具程序。一般來說,安裝了 Linux 后,就會有 md5sum 這
個工具,直接在命令行終端直接運行。
1.使用 md5sum 來產生報文摘要命令如下:
md5sum file > file.md5 或 md5sum file >> file.md5
也可以把多個文件的報文摘要輸出到一個文件中,這需要使用通配符 * ,比如某目錄下有幾個 iso 文件,要把這幾個iso
文件的報文摘要輸出到 iso.md5 文件中,命令如下:
md5sum *.iso > iso.md5
2.使用 md5 報文摘要驗證文件
2.1 把下載的文件 file 和 該文件的 file.md5 報文摘要放在同一個目錄下,然后用如下命令進行驗證:
md5sum -c file.md5
2.2 使用 md5sum file 命令會輸出一個 md5 的報文摘要,然后把這個報文摘要直接與 file.md5 中的內容比較。
示例如下:
[root@VM_81_181_centos ~]# mkdir test [root@VM_81_181_centos ~]# cd test/ [root@VM_81_181_centos test]# touch f1.txt f2.txt [root@VM_81_181_centos test]# ls f1.txt f2.txt [root@VM_81_181_centos test]# md5sum *.txt > md5sumtest.md5 [root@VM_81_181_centos test]# cat md5sumtest.md5 d41d8cd98f00b204e9800998ecf8427e f1.txt d41d8cd98f00b204e9800998ecf8427e f2.txt [root@VM_81_181_centos test]# echo "hahaha" > f1.txt [root@VM_81_181_centos test]# md5sum -c md5sumtest.md5 f1.txt: FAILED f2.txt: OK md5sum: WARNING: 1 computed checksum did NOT match [root@VM_81_181_centos test]# echo "hahaha" > f2.txt [root@VM_81_181_centos test]# md5sum -c md5sumtest.md5 f1.txt: FAILED f2.txt: FAILED md5sum: WARNING: 2 computed checksums did NOT match [root@VM_81_181_centos test]# cat /dev/null > f1.txt [root@VM_81_181_centos test]# md5sum -c md5sumtest.md5 f1.txt: OK f2.txt: FAILED md5sum: WARNING: 1 computed checksum did NOT match [root@VM_81_181_centos test]# cat /dev/null > f2.txt [root@VM_81_181_centos test]# md5sum -c md5sumtest.md5 f1.txt: OK f2.txt: OK [root@VM_81_181_centos test]#
生成一個文件的 md5 值
[root@VM_81_181_centos test]# md5sum f1.txt d41d8cd98f00b204e9800998ecf8427e f1.txt
總結
以上是生活随笔為你收集整理的Linux md5sum 的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 编辑数学公式_Jupyte
- 下一篇: C++之“偏正短语”