目錄

利用 Linux command 取得檔案 hash 值

Note
hash 值是經過特定的演算法,取得資料的唯一值,是不可逆的函數,也就是說無法利用 hash 值來回推原本的檔案內容。利用 hash 值的特性可以用來判斷檔案是否有異動,比較是否為相同的檔案。

之前介紹了 Windows 中取得檔案 hash 值的方式。在這邊列出幾個 Linux 上取得 hash 值的指令。

下面指令 <your file> 需要換成要產生 hash 值的檔名,或是使用 * 來產生當前路徑下所有檔案的 hash 值。

md5sum

使用 md5sum 取得檔案的 MD5 值。

md5sum <your file> 

sha1sum

sha1sum 取得檔案的 SHA1 值。

sha1sum <your file> 

sha256sum

使用 sha256sum 取得檔案的 SHA256 值。

sha256sum <your file> 

結論

利用上述提到的幾個指令,可以產生檔案 hash 值,整體來說算簡單好記。指令加上 file path 即可。

延伸閱讀

參考資料