Create archive

Written by on .

Using zip

Use the following command to create a zip-file from a given directory (/path/to/directory):

cd /path/to/ && zip -r -y - directory >archive.zip

Using tar

Use the following command to create a tar-file from a given directory (/path/to/directory):

cd /path/to/ && tar -c directory >archive.tar.gz

Tar is uncompressed by default, pipe to gzip to create a tar.gz-file (gzipped):

cd /path/to/ && tar -c directory | gzip -c >archive.tar.gz

Attributes

Basic permissions and file time statistics are preserved. But other attributes that are not stored within the file, are not preserved unless an option for this is explicitly added. Attributes that are not preserved include:

Add --xattr to tar to preserve extended attributes (both for compression and extraction).