Create project.tar.gz from the project directory using gzip compression.
Keep the original directory.
Which GNU tar command is appropriate?
tar -czf ARCHIVE SOURCE creates an archive and compresses it with gzip. The source directory remains unchanged.
Detailed explanation
tar -czf project.tar.gz projectCorrect. tar -czf project.tar.gz project creates the gzip-compressed archive.
Correct. tar -czf project.tar.gz project creates the gzip-compressed archive.
tar -xzf project.tar.gz projectIncorrect. -x extracts an archive rather than creating one.
Incorrect. -x extracts an archive rather than creating one.
tar -cjf project.tar.gz projectIncorrect. -j selects bzip2, not gzip.
Incorrect. -j selects bzip2, not gzip.
tar -cJf project.tar.gz projectIncorrect. -J selects xz, not gzip.
Incorrect. -J selects xz, not gzip.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); mkdir "$tmp/project"; printf data >"$tmp/project/item"; (cd "$tmp" && tar -czf project.tar.gz project && tar -tzf project.tar.gz); rm -rf "$tmp"Expected result
project/とproject/itemを含む一覧Key points
- c creates
- z means gzip
- f is followed by archive name
Notes
- Environment: GNU tar 1.x / gzip / 一時ディレクトリ
- 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.