0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ファイルの内容が同じか確認する方法(ハッシュ値を比較)

Posted at

Linux環境でファイル内容の正しさを比較するときどうしてますか?

diffコマンド使うのが多いかと思います。
ですが、
・バイナリファイル同士の同一性を確認できない
・行のわずかな変更や行の順序の差分を検知してしまう(内容が一致してても、順序が異なれば差分としてでてしまう)
という課題がある。

単純にデータの内容の一致を確認したい場合、
sha1sumコマンドを使うことで、
引数に指定したファイルの、SHA1アルゴリズムでの計算されたハッシュ値を表示することができるので、
そのハッシュ値を比較して一致すればファイルの中身は同一であることを保証できる。

コマンド概要

sha1sum ファイル名

コマンド実行例

# sha1sum sample_1.txt
384a8a9f6c477b7be4999dd5118558c32a8ce1b8 sample_1.txt

比較対象のもう一つのファイル

# sha1sum sample_2.txt
384a8a9f6c477b7be4999dd5118558c32a8ce1b8 sample_2.txt

384a8a9f6c477b7be4999dd5118558c32a8ce1b8
が一致するため、ファイル内のデータが同一であると判断できる

※参考サイト
https://eng-entrance.com/linux-command-sha1sum#MD

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?