To tar and gzip a folder, the syntax is:
tar czf name_of_archive_file.tar.gz name_of_directory_to_tar
The -
with czf
is optional.
If you want to tar
the current directory, use .
to designate that.
To construct filenames dynamically, use the date
utility (look at its man page for the available format options). For example:
cd /var/www &&
tar czf ~/www_backups/$(date +%Y%m%d-%H%M%S).tar.gz .
This will create a file named something like 20120902-185558.tar.gz
.
On Linux, chances are your tar
also supports BZip2 compression with the j
rather than z
option. And possibly others. Check the man page on your local system.
-c, --create
create a new archive
-x, --extract, --get
extract files from an archive
-v, --verbose
verbosely list files processed
-z, --gzip
filter the archive through gzip
-j, --bzip2
filter the archive through bzip2
-J, --xz
filter the archive through xz
-f, --file=ARCHIVE
use archive file or device ARCHIVE