Official documentation

GNU tar manual - GNU Project - Free Software Foundation

TLDR

The tar utility is used to work with archive files and has 8 modes of operation and several options, the utility has a special (non-standard) syntax order which DOES NOT CONFORM TO NORMAL command line usage, pay extra attention to your command arguments (see operations vs options below)! The most used operations are "--create or -c", "--list or -t" and "--extract or -x". The command has a long form, short form and old form syntax, all three styles/syntaxes may be intermixed in a single tar command. One operation must be specified and only one operation can be used at a time. Several or no options can be used for each operation. Some options only make sense together with one type of (contextual) operation. The options "--file or -f", "--verbose or -v" and "--compress or -Z" are the most frequently used options and work for all operational modes.

Examples

tar [operation] [option] [file.tar] [input]/[output]

Extracting archives/"untarring"/"unzipping tar files" -x

tar -xvf [tar-file.tar] [output]
tar -xvf album.tar #extracts the entire archive 
tar -xvf album.tar photos #extracts the folder or file "photos" in album.tar
tar xvf album.tar photos #old style flags

Listing files in archives -t

tar -tvf [tar-file.tar] 
tar tvf [tar-file.tar] #old style
tar -tvf [tar-file.tar] subfolder

Creating archives/"tarring"/"zipping tar files" -c

tar [tar-file.tar] [input] ... [input]
tar -cvf album.tar photo1 photo2 photo3 #tarring individual files or folders
tar cvf album.tar photo1 photo2 photo3 #old style flags
tar -cvf album.tar photos/ pictures/ #tarring folders

Documentation highlights

Core Functionality/Operations

  • Create
  • List
  • Extract
  • append
  • compare
  • concatenate
  • delete
  • update

Frequently used options

  • File
  • Verbose
  • Compress

Important stuff

  • tar can direct its output to available devices, files, or other programs (using pipes).
  • Archives created by tar are capable of preserving file information and directory structure.
  • Conventionally, tar archives are given names ending with ‘.tar’.  This convention can be broken and is not necessary for tar to operate.
  • Whenever you use ‘create’, tar will erase the current contents of the file named by ‘--file=archive-name’ (‘-f archive-name’) if it exists.
  • TARs first argument must be an option
  • The order of the options becomes more important when you begin to use short forms.  

Definitions

  • An archive is a single file which contains the contents of many files, while still identifying the names of the files, their owner(s), and so forth.
  • The files inside an archive are called members.
  • The term extraction refers to the process of copying an archive member (or multiple members) into a file in the file system.

Definition - Operations vs Options TAR.

  • Arguments to tar fall into one of two classes: operations, and options. Operations; exactly one of these is both allowed and required for any instance of using tar; you may not specify more than one. Options; You are not required to specify any options, and you are allowed to specify more than one at a time (depending on the way you are using tar at that time).

Gotchas

  • The order of the options becomes more important when you begin to use short forms.  
  • List the arguments in the order that makes the commands easiest to understand.
 $ tar -cfv collection.tar blues folk jazz

In this case, tar will make an archive file called ‘v’, containing the files ‘blues’, ‘folk’, and ‘jazz’, because the ‘v’ is the closest “file name” to the ‘-f’ option, and is thus taken to be the chosen archive file name.  tar will try to add a file called ‘collection.tar’ to the ‘v’ archive file; if the file ‘collection.tar’ did not already exist, tar will report an error indicating that this file does not exist.  If the file ‘collection.tar’ does already exist (e.g., from a previous command you may have run), then tar will add this file to the archive. Because the ‘-v’ option did not get registered, tar will not run under ‘verbose’ mode, and will not report its progress.