The common usage of the tar command within in Linux is the creation of .tar.gz. or even .tgz archive files. These archive files are also known as tarballs. This tar command has a vast array of options to use but all you need to remember is a couple of letters in order to efficiently create and extract your archive files using tar.
For starters the tar command GNU which is included within the Linux program comes with integrated compression. This means that it is able to create a .tar archivable file and then compress it into a bzip2 or gzip using one command. You will use the following set of coding to compress either an entire directory of files or even just one file within Linux. It is also equipped to compress all the directories inside of the specific directory that you are compressing. It has the ability to work recursively.
code; tar-czvf name-of-archive.tar.gz/path/to/directory-or-file
When broken down this is what the coding actually means;
-c ; you are creating an archive
-z ; you are compressing and archive using gzip
-v ; is a display of progress in the terminal when creating the archive itself aka verbose mode. the -v is considered optional but it will aid you
-f ; this allows you to decide the filename of the given archive
For example - you own a directory labeled stuff in but you would like to save it within a filed titled archive.tar.gz. The following coded command would look like this..
code; tar-czvf archive.tar.gz stuff
In order to compress more then one file at once all you will need to do is list all of the files or directories in place of writing a single one. It is as simple as that. For instance you will type the list as /home/ubuntu/downloadsdirectory, the/usr/local/stuff directory and /home/ubuntu/documents/notes.txt file. The code would look as follows..
code; tar-czvf archive.tar.gz/home/unbuntu/downloads/usr/local/stuff/home/ubuntu/documents/notes.txt
In order to extract an archive that currently exist you may also use the tar command. The following command will be able to preform the extraction of the contents of said archive.tar.gz in the existing directory.
code; tar-xzvf archive.tar.gz
It is the same context and creating as used above the only difference is that the -x replaces the -c switch. This -x specifically commands the extraction of an archive instead of the creation of one.
All explained above is the simplest form of usage for the tar command. There are a vast amount of options that are available within the tar command. For further info about the run of the tar command view the tar commands online manual.