Compress report.log to create report.log.gz.
Keep the original report.log as well.
Which command is appropriate?
gzip -k keeps the input file after compression. Without -k, normal gzip operation replaces the input with the compressed file.
Detailed explanation
gunzip report.logIncorrect. gunzip is a decompression command.
Incorrect. gunzip is a decompression command.
gzip report.logIncorrect. Plain gzip normally removes the original after successful compression.
Incorrect. Plain gzip normally removes the original after successful compression.
zcat report.log > report.log.gzIncorrect. zcat reads compressed input and does not compress this plain log file.
Incorrect. zcat reads compressed input and does not compress this plain log file.
gzip -k report.logCorrect. -k creates report.log.gz and preserves report.log.
Correct. -k creates report.log.gz and preserves report.log.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
printf demo > "$LAB_DIR/report.log"
gzip -k "$LAB_DIR/report.log"
test -f "$LAB_DIR/report.log" -a -f "$LAB_DIR/report.log.gz" && echo BOTH
rm -r "$LAB_DIR"Expected result
BOTHKey points
- gzip creates .gz
- -k keeps the input
- gunzip is for decompression
Notes
- Environment: GNU gzip 1.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.