Linux create archives using gzip or bzip2 compression.How to

Linux Tar commandYou can use the tar command on Ubuntu to create .tar.gz or .tgz archive files. These archives are usually called ‘tarballs’. Tar is a Unix Archive file format. It is designed primarily for Unix computers, but now many software including Windows software could work with Tar archives. You can find the command included in Ubuntu. It has a lot of options, but you just need to learn a few of them to create archives and extract files. You can create archives using gzip or bzip2 compression.How to archive files using the Tar?To compress a file or directory on Ubuntu or Linux you can use the following command. This command also compress every other directory inside a directory you specify.tar -czvf archive-name.tar.gz /path/directory-or-fileWe use the following options:-c: Create an archive. -z: Compress the archive with gzip. -v: Display progress in the terminal while creating the archive (so called “verbose” mode). -f: Allows you to specify the filename of the archive.How to archive multiple files or directories by Tar command?You can also compress multiple directories or files by providing a list of files or directories.tar -czvf archive-name.tar.gz /path/directory-or-file-1 /path/directory-or-file-2 /path/directory-or-file-3How to exclude directories and files from Tar archive?If you would like to compress an entire directory, but exclude some files or directories, you can use option –exclude.tar -czvf archive-name.tar.gz /path/directory-or-file –exclude=/path/directory-or-file-excludeHow to make bzip2 compression Tar archive?Gzip compression is more frequent, but sometimes you may want to compress archive using bzip compression algorithm.  You can do so just replacing the -z option for gzip with a -j for bzip2 in the command line. Gzip is faster, but bzip2 generally compresses better and you can get smaller size of archive file.tar -cjvf archive-name.tar.gz /path/directory-or-file How to list files of Tar Archive?You can use -t option to list the contents of an archive.tar -ztvf archive-name.tar.gzHow to extract files using the Tar? You can extract files from archive by using -x option:tar -xzvf archive-name.tar.gzThe options for this command are:-x: extract an archive. -z: extract the files from archive with gzip. -v: display progress in the terminal while creating the archive (so called “verbose” mode). -f: Allows you to specify the filename of the archive.You can specify the particular directory to extract the contents of the archive. Appending the -C option to the end of the command line:tar -xzvf archive-name.tar.gz -c /path/directory