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.
tar -xzf project.tar.gz projectIncorrect. -x extracts an archive rather than creating one.
tar -cjf project.tar.gz projectIncorrect. -j selects bzip2, not gzip.
tar -cJf project.tar.gz projectIncorrect. -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 / 一時ディレクトリ
- 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
Creating a gzip-compressed archive requires the create operation, gzip selection, and an output archive name.
Check the side effect
List the archive after creation to confirm that the expected members were stored.