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
-rrecurse into directories
-ydon't follow symlinks, store literal symbolic links
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
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:
- Filesystem file attributes such as immutable (chattr, lsattr).
- Extended attributes (xattr), including SELinux contexts and Access Control Lists (ACL) which are typically stored in xattr.
tar to preserve extended attributes (both for compression and extraction).