Skip to main content
tar

GNU tar Option Styles

By March 6, 2018September 12th, 2022No Comments

GNU tar option stylesWhen you are starting to learn the Linux archiving command tar, the best starting point is to start to discover the GNU tar option styles. These are long, short and old. In this blog we take you gently into tar by investigating these styles. The second tutorial looks at creating archives in a little more detail.

What is GNU Tar

GNU tar is used to create and manage archives. An archive is a collection of files and include normal files, links and directories as well as other file types.  Archives make use of the extension, ( or suffix ), of .tar. The tar command allows users a method to control large amounts of files easily as a single unit.

The main command line options with tar include:

–create Used to create a new archive file and can also be represented with -c

–list Used to list the archive contents, or which files are included in the .tar file. The short option for this is -t

–extract Used to restore archives and can be represented with the short option -x

What are the GNU tar Option Styles

GNU tar can make use of 3 options styles, long, short and old. This manual will make most use of the long style as this becomes easier to read and understand. The short style is, by it’s very name, shorter to type but the options are not as obvious to comprehend. Just look at the –list option above which has the short option of -t. The short option is not immediately obvious. The old options is less used making use of the short option without the dashes. In the following example we will show each option style used when adding two common Linux files to an archive. Running the command from your home directory, we combine the files /etc/hosts and /etc/services into a single archive named hosts.tar. We overwrite the existing archive each time the command is executed. So, even though the command will be executed 4 times in total, we will have single archive with just the 2 files we have selected.:

long The long style make use of a full option name preceded with the double-dash and, as such, helps the readability of the command. The downsize is the length of the command line string needed to be typed:

$ tar --create --file=hosts.tar /etc/hosts /etc/services

short The short style make use of the single dash rather than the double dash and a single character to represent the option. This leads to shorter options but less readability. Options can be combined with a single dash as illustrated in the second example:

$ tar -c -f hosts.tar /etc/hosts /etc/services
$ tar -cf hosts.tar /etc/hosts /etc/services

old Now, it is my guess, that the name old may give some clues here, inferring that it certainly is not preferred. The old style is the same as the short style, just not making use of the dash. This can be confusing making it hard to understand and be able to differentiate the options from clues supplied to those options. Using the old style the options cannot be separated rather they must be concatenated as below without spaces:

$ tar cf hosts.tar /etc/hosts /etc/services

The video follows: