Archives, checksums and temporary files
An archive groups files; compression reduces representation size when possible. GNU tar -cf creates an archive, -tf lists members, and -czf creates a gzip-compressed archive. Use only explicit owned inputs and a new archive path: creation can overwrite an old archive. Do not extract untrusted archives into an existing workspace; review provenance, paths, links and resource limits first. sha256sum calculates a content digest, and -c checks against a recorded digest. A matching digest does not authenticate data unless the expected digest is trusted. mktemp -d creates a fresh directory; use a checked result, quote it, and remove only the known fixture files when done. Do not use predictable shared temporary paths. Check each write, archive creation and checksum generation before reading the result. If the temporary-file example fails before its cleanup, a private fixture directory may remain; inspect it in the disposable workspace. It does not promise cleanup after every signal or failure.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Create and inspect an archive
mkdir reports || exit 1printf 'ready\n' > reports/status.txt || exit 1tar -czf bundle.tar.gz reports/status.txt || exit 1tar -tf bundle.tar.gzExpected stdout:
reports/status.txtThe archive has one explicit member. This lists it without extraction.
Verify a saved digest
printf 'ready\n' > report.txt || exit 1sha256sum report.txt > checksums.txt || exit 1sha256sum -c checksums.txtExpected stdout:
report.txt: OKThe content matches the locally saved digest. It does not prove who created it.
Allocate and clean a temporary workspace
work=$(mktemp -d ./bm.XXXXXXXX) || exit 1printf 'temporary\n' > "$work/note.txt" || exit 1cat -- "$work/note.txt" || exit 1rm -- "$work/note.txt" && rmdir -- "$work" || exit 1printf 'cleaned\n'Expected stdout:
temporarycleanedOnly a known file and its now-empty directory are removed. A failed cleanup is reported as failure.
Common mistakes
A checksum is not a signature. Do not archive an entire home directory, extract unknown archives, or use an unvalidated path with recursive removal.
Practice
In a fresh directory create two tiny text files, build a compressed archive, list its members and check its saved digest. Modify a separate copy of the archive and observe verification failure without extracting it.
Next: GNU, BSD and BusyBox utility differences