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.
Incorrect. gzip creates a gzip file rather than an xz file.
bzip2 -k large.logIncorrect. bzip2 creates a bzip2 file rather than xz.
Incorrect. bzip2 creates a bzip2 file rather than xz.
xz -k large.logCorrect. xz -k large.log creates the compressed file and retains the input.
Correct. xz -k large.log creates the compressed file and retains the input.
xz -d large.logIncorrect. -d requests decompression.
Incorrect. -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 / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.