Create backup.tar.gz containing project/config.
Archive members should start at config rather than project/config.
Which command is appropriate?
tar -C changes the working directory for the following path, so the parent directory name is not stored in the member path.
Detailed explanation
tar -czf backup.tar.gz projectIncorrect. Adding project stores the project directory prefix.
Incorrect. Adding project stores the project directory prefix.
tar -czf backup.tar.gz -C project configCorrect. -C project changes the base directory before adding config.
Correct. -C project changes the base directory before adding config.
tar -czf backup.tar.gz project/config/app.confIncorrect. The explicit path keeps the project prefix in the archive.
Incorrect. The explicit path keeps the project prefix in the archive.
tar -xzf backup.tar.gz -C project configIncorrect. -x extracts an archive instead of creating one.
Incorrect. -x extracts an archive instead of creating one.
Try it yourself
An example you can run in a temporary verification environment.
mkdir -p project/config
printf 'mode=demo
' > project/config/app.conf
tar -czf backup.tar.gz -C project config
tar -tzf backup.tar.gzExpected result
config/
config/app.confKey points
- tar member names
- The -C directory change
- Create versus extract mode
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.