The restore directory exists.
Extract backup.tar.gz into restore.
Which GNU tar command is appropriate?
tar -xzf extracts a gzip-compressed tar archive. -C changes the directory in which extraction is performed.
Detailed explanation
tar -czf backup.tar.gz -C restoreIncorrect. -c creates an archive rather than extracting one.
Incorrect. -c creates an archive rather than extracting one.
tar -tzf backup.tar.gz -C restoreIncorrect. -t lists archive contents without extracting them.
Incorrect. -t lists archive contents without extracting them.
tar -xjf backup.tar.gz -C restoreIncorrect. -j selects bzip2, not gzip.
Incorrect. -j selects bzip2, not gzip.
tar -xzf backup.tar.gz -C restoreCorrect. -xzf extracts the gzip tar archive under restore.
Correct. -xzf extracts the gzip tar archive under restore.
Try it yourself
An example you can run in a temporary verification environment.
LAB_DIR=$(mktemp -d)
mkdir "$LAB_DIR/source" "$LAB_DIR/restore"
printf demo > "$LAB_DIR/source/file"
tar -czf "$LAB_DIR/backup.tar.gz" -C "$LAB_DIR/source" file
tar -xzf "$LAB_DIR/backup.tar.gz" -C "$LAB_DIR/restore"
cat "$LAB_DIR/restore/file"
rm -r "$LAB_DIR"Expected result
demoKey points
- -x extracts
- -z selects gzip
- -C changes the extraction directory
Notes
- Environment: GNU tar 1.35
- 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.