How do I compare text files and check whether two downloads are identical?
Use diff to see line-by-line text changes and sha256sum to compare file bytes. A matching digest is useful evidence that the bytes match a trusted expected value. A checksum supplied alongside a compromised download is not independent proof of its origin.
Before you start
- An authorised SSH session on the Linux server.
Instructions
1. Compare two existing text versions
Choose files that are already available for review; no extra copy is created by this command. Unified output shows a short context around additions and removals.
diff -u -- "$HOME/server-notes/version-a.txt" "$HOME/server-notes/version-b.txt"Lines prefixed with - or + describe differences. Exit status 0 means equal, 1 means different, and a greater status indicates a comparison error.
2. Check downloaded file bytes
Compute the digest for the exact downloaded file and compare the complete result with a value obtained through the publisher’s trusted distribution process.
sha256sum -- "$HOME/server-notes/package.tar.gz"The hexadecimal digest covers file contents, not its filename, permissions, author or safety. Prefer the publisher’s signed verification process when available.
Check the result
- The text differences are expected, or the entire SHA-256 value matches the independently trusted value. Recheck after any transfer or modification.
Troubleshooting
- A text file differs only after a Windows transfer
- Line endings or encoding may have changed. Inspect the format rather than assuming the application change is harmless.
- The digest differs
- Stop using that file and verify the download, version and expected digest.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
