Files
lk/data/archives.md

1.2 KiB

title, tags
title tags
Archives
archives
backups

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'.