linux命令之md5sum
1.md5sum介紹
linux命令md5sum是用來計(jì)算和校驗(yàn)文件的MD5值。
另外:
md5sum是用來校驗(yàn)文件內(nèi)容,與文件名是否相同無關(guān)
md5sum校驗(yàn)文件時(shí),逐位校驗(yàn),如果文件越大,校驗(yàn)所需時(shí)間就越長
2.md5sum用法
md5sum [參數(shù)] filename
參數(shù) | 說明 |
-b | 以二進(jìn)制模式讀入文件內(nèi)容 |
-t | 以文本模式讀入文件內(nèi)容 |
-c | 從指定文件中讀取 MD5 校驗(yàn)和,并進(jìn)行校驗(yàn) |
--status | 不生成[爭取/錯(cuò)誤]提示信息,通過命令返回值來判斷 |
3.實(shí)例
3.1.查看md5sum幫助信息
命令:
md5sum --help
[root@rhel77 ~]# md5sum --help
Usage: md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.
With no FILE, or when FILE is -, read standard input.
-b, --binary read in binary mode
-c, --check read MD5 sums from the FILEs and check them
--tag create a BSD-style checksum
-t, --text read in text mode (default)
Note: There is no difference between binary and text mode option on GNU system.
The following four options are useful only when verifying checksums:
--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 display this help and exit
--version output version information and exit
The sums are computed as described in RFC 1321. When checking, the input
should be a former output of this program. The default mode is to print
a line with checksum, a character indicating input mode ('*' for binary,
space for text), and name for each FILE.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'md5sum invocation'
[root@rhel77 ~]#
3.2.檢查文件md5值
命令:
md5sum -t ztj.txt
OR
md5sum -b ztj.txt
root@rhel77 ~]# md5sum -t ztj.txt
cfc12d1432a7b067566080122b1c4f85 ztj.txt
[root@rhel77 ~]# md5sum -b ztj.txt
cfc12d1432a7b067566080122b1c4f85 *ztj.txt
[root@rhel77 ~]#
3.3.檢查文件md5值,與文件無關(guān)
命令:
\cp ztj.txt ztj.txt.bak
md5sum ztj.txt
md5sum ztj.txt.bak?
root@rhel77 ~]# \cp ztj.txt ztj.txt.bak
[root@rhel77 ~]# md5sum ztj.txt
cfc12d1432a7b067566080122b1c4f85 ztj.txt
[root@rhel77 ~]# md5sum ztj.txt.bak
cfc12d1432a7b067566080122b1c4f85 ztj.txt.bak
[root@rhel77 ~]#
3.4.從指定文件中讀取MD5校驗(yàn)和,并進(jìn)行校驗(yàn)
命令:
md5sum ztj.txt >> md5sum.txt
md5sum -c md5sum.txt
[root@rhel77 ~]# md5sum ztj.txt >> md5sum.txt
[root@rhel77 ~]#
[root@rhel77 ~]# md5sum -c md5sum.txt
ztj.txt: OK
[root@rhel77 ~]#
3.5.從指定文件中讀取MD5校驗(yàn)和,并不顯示校驗(yàn)信息,以命令返回值來判斷
備注:
如果校驗(yàn)一致返回0,不一致返回1
命令:
md5sum -c --status md5sum.txt文章來源:http://www.zghlxwxcb.cn/news/detail-726558.html
echo $?文章來源地址http://www.zghlxwxcb.cn/news/detail-726558.html
[root@rhel77 ~]# md5sum -c --status md5sum.txt
[root@rhel77 ~]# echo $?
0
[root@rhel77 ~]#
OR
命令:
echo 111 >>ztj.txt
md5sum -c --status md5sum.txt
echo $?
[root@rhel77 ~]# echo 111 >>ztj.txt
[root@rhel77 ~]#
[root@rhel77 ~]# md5sum -c --status md5sum.txt
[root@rhel77 ~]# echo $?
1
[root@rhel77 ~]#
到了這里,關(guān)于Linux命令(109)之md5sum的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!