Create large.log.xz from large.log.
Keep large.log after compression.
Which command is appropriate?
xz -k creates the compressed .xz output and keeps the input file. -d selects decompression.
Detailed explanation
gzip -k large.logIncorrect. gzip creates a gzip file rather than an xz file.
bzip2 -k large.logIncorrect. bzip2 creates a bzip2 file rather than xz.
xz -k large.logCorrect. xz -k large.log creates the compressed file and retains the input.
xz -d large.logIncorrect. -d requests decompression.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); printf 'sample sample sample\n' >"$tmp/large.log"; xz -k "$tmp/large.log"; test -f "$tmp/large.log" && test -f "$tmp/large.log.xz" && echo both-exist; rm -rf "$tmp"Expected result
both-existKey points
- xz format
- -k keeps input
- -d decompresses
Notes
- Environment: XZ Utils 5.x / 一時ファイル
- Use disposable files and directories for destructive or timestamp-related checks.
- Command details can vary slightly between GNU and non-GNU implementations.
Foundation review
Place the operation
The format determines the output suffix and decoder, while input retention is controlled by a separate option.
Check the side effect
Confirm that both the compressed output and original input exist after a disposable test.