1.2 KiB
title, tags
| title | tags | ||
|---|---|---|---|
| Archives |
|
Create
Combine many files and directories into a single t-archive file.
tar cf "$ARCHIVE".tar $DIR
You can remember this with the mnemonic 'Create File'.
Unfortunately, this stores the full file path, so making a tar archive of /etc/nginx/ will store etc/nginx (without the leading /).
It's often better to tell tar which path to start from using the -C flag.
tar cf "$ARCHIVE".tar -C /etc/ nginx
Check the contents of your archive with:
tar tf "$ARCHIVE".tar
If you want to store 'everything in a directory', then using * will not work, because it will target everything in the current directory.
Instead, you can store the target in a variable:
files=$(ls /etc/nginx)
tar cf "$ARCHIVE".tar -C /etc/nginx/ $file
Extract
Extract the tar archive with
tar xf "$ARCHIVE".tar
You can remember this with the mnemonic 'eXtract File'.
Compress
Create a zip-compressed archive with the z flag.
tar czf "$ARCHIVE".tgz -C /etc/nginx/ $file
You can use any file ending you want, but sane people like to use '.tgz' or '.tar.tgz'.