Store, list or extract files in an archive (originally on tape - Tape ARchiver).

      tar [[-]function] [options] filenames...

      tar [[-]function] [options] -C directory-name...

   Command-line arguments that specify files to add to, extract from,
   or list from an archive can be given as shell pattern matching strings.

     Exactly one of the following functions (shown in bold) must be specified:
     --concatenate  Append the contents of named file, which must itself be a
      gnutar archive, to the end of the archive (erasing the old
      end-of-archive block).  This has the effect of adding the
      files contained in the named file to the first archive,
      rather than adding the second archive as an element of the
      first.  Note: This option requires a rewritable tarfile,
      and therefore does not work on quarter-inch cartridge
      tapes.  (see notes below)
     --create     Create a new archive (or truncate an old one) and write
                   the named files to it.
     --compare     Find differences between files in the archive and
                   corresponding files in the file system.

     --delete     Delete named files from the archive.
                  (Does not work on quarter-inch tapes).
     --append     Append files to the end of an archive.
                  (Does not work on quarter-inch tapes).
     --list     List the contents of an archive; if filename arguments are
                   given, only those files are listed, otherwise the entire
                   table of contents is listed.

     --test-label     test the archive volume label and exit

     --update     Append the named files if the on-disk version has a 
                   modification date more recent than their copy in the 
                   archive(if any).  Does not work on quarter-inch tapes.
     --get         Extract files from an archive.  The owner, modification
                   time, and file permissions are restored, if possible.  If
                   no file arguments are given, extract all the files in the
                   archive.  If a filename argument matches the name of a
                   directory on the tape, that directory and its contents are
                   extracted (as well as all directories under that direc-
                   tory).  If the archive contains multiple entries corre-
                   sponding to the same file (see the --append command
                   above), the last one extracted will overwrite all earlier

     -C, --directory=DIR     change to directory DIR

     -f, --file=ARCHIVE     use archive file or device ARCHIVE

     -j, --bzip2     filter the archive through bzip2

     -J, --xz     filter the archive through xz

     -p, --preserve-permissions     extract information about file permissions (default for superuser)

     -v, --verbose     verbosely list files processed.

     -z, --gzip     filter the archive through gzip 

You can specify an argument for `--file (or -f ) whenever you use tar; this option determines the name of the archive file that `tar' will work on.

If you don't specify this argument, then `tar' will use a default, usually some physical tape drive attached to your machine. If there is no tape drive attached, or the default is not meaningful, then `tar' will print an error message like one of the following:

     tar: can't open /dev/rmt8 : No such device or address
     tar: can't open /dev/rsmt0 : I/O error

To avoid confusion, we recommend that you always specify an archive file name by using `--file=ARCHIVE-NAME' (or `-f ARCHIVE-NAME') when writing your `tar' commands.

     --verbose' (`-v') shows details about the results of running `tar'.

This can be especially useful when the results might not be obvious. For example, if you want to see the progress of `tar' as it writes files into the archive, you can use the `--verbose' option. In the beginning, you might find it useful to use `--verbose' at all times; when you are more accustomed to `tar', you will likely want to use it at certain times but not at others.

Sometimes, a single instance of `--verbose' on the command line will show a full, `ls' style listing of an archive or files, giving sizes, owners, and similar information. Other times, `--verbose' will only show files or members that the particular operation is operating on at the time. In the latter case, you can use `--verbose' twice in a command to get a listing such as that in the former case.


     Normally when creating an archive, `tar' strips an initial `/' from
     member names.  This option disables that behavior.

     (See --newer.)

     Tells `tar' to preserve the access time field in a file's inode
     when dumping it.

     Rather than deleting files from the file system, `tar' will back
     them up using simple or numbered backups, depending upon

     With this option present, `tar' prints error messages for read
     errors with the block number in the archive file.

     Sets the blocking factor `tar' uses to BLOCKING x 512 bytes per

     This option tells `tar' to read or write archives through `bzip2'.

     This option directs `tar' to print periodic checkpoint messages as
     it reads through the archive.  Its intended for when you want a
     visual indication that `tar' is still running, but don't want to
     see --verbose' output.

     `tar' will use the `compress' program when reading or writing the
     archive.  This allows you to directly act on archives while saving

     (See --interactive.)

     When creating a `tar' archive, `tar' will archive the file that a
     symbolic link points to, rather than archiving the symlink.

     When this option is specified, `tar' will change its current
     directory to DIR before performing any operations.  When this
     option is used during archive creation, it is order sensitive.

     When performing operations, `tar' will skip files that match

     Similar to --exclude, except `tar' will use the list of patterns
     in the file FILE.

     `tar' will use the file ARCHIVE as the `tar' archive it performs
     operations on, rather than tar's compilation dependent default.

     `tar' will use the contents of FILE as a list of archive members
     or files to operate on, in addition to those specified on the

     Forces `tar' to interpret the filename given to --file as a local
     file, even if it looks like a remote tape drive name.

     Files added to the `tar' archive will have a group id of GROUP,
     rather than the group from the source file.  GROUP is first decoded
     as a group symbolic name, but if this interpretation fails, it has
     to be a decimal numeric group ID.

     Also see the comments for the --owner=USER option.

     This option tells `tar' to read or write archives through `gzip',
     allowing `tar' to directly operate on several kinds of compressed
     archives transparently.

     `tar' will print out a short message summarizing the operations and
     options to `tar' and exit.

     Instructs `tar' to exit successfully if it encounters an
     unreadable file. 

     (See --preserve-permissions'; *note Writing::..)

     With this option, `tar' will ignore zeroed blocks in the archive,
     which normally signals EOF.  *Note Reading::.

     Used to inform `tar' that it is working with an  old GNU-format
     incremental backup archive.  It is intended primarily for backwards
     compatibility only.

     When `tar' is performing multi-tape backups, SCRIPT-FILE is run at
     the end of each tape.

     Specifies that `tar' should ask the user for confirmation before
     performing potentially destructive options, such as overwriting

     When extracting files from an archive, `tar' will not overwrite
     existing files if this option is present.  *Note Writing::.

     When creating an archive, instructs `tar' to write NAME as a name
     record in the archive.  When extracting or listing archives, `tar'
     will only operate on archives that have a label matching the
     pattern specified in NAME.

     During a --create' operation, specifies that the archive that
     `tar' creates is a new GNU-format incremental backup, using
     SNAPSHOT-FILE to determine which files to backup.  With other
     operations, informs `tar' that the archive is in incremental

     When adding files to an archive, `tar' will use PERMISSIONS for
     the archive members, rather than the permissions from the files.
     The program `chmod' and this `tar' option share the same syntax
     for what PERMISSIONS might be.  *Note Permissions: (fileutils)File
     permissions.  This reference also has useful information for those
     not being overly familiar with the Unix permission system.

     Of course, PERMISSIONS might be plainly specified as an octal
     number.  However, by using generic symbolic modifications to mode
     bits, this allows more flexibility.  For example, the value `a+rw'
     adds read and write permissions for everybody, while retaining
     executable bits on directories or on any other file already marked
     as executable.

     Informs `tar' that it should create or otherwise operate on a
     multi-volume `tar' archive.

     (see -info-script)

     When creating an archive, `tar' will only add files that have
     changed since DATE.

     In conjunction with --newer', `tar' will only add files whose
     contents have changed (as opposed to just --newer', which will
     also back up files for which any status information has changed).

     With this option, `tar' will not recurse into directories unless a
     directory is explicitly named as an argument to `tar'.

     When `tar' is using the --files-from' option, this option
     instructs `tar' to expect filenames terminated with `NUL', so
     `tar' can correctly work with file names that contain newlines.

     This option will notify `tar' that it should use numeric user and
     group IDs when creating a `tar' file, rather than names.

     (See --portability.)

     Used when creating an archive.  Prevents `tar' from recursing into
     directories that are on different file systems from the current

     Specifies that `tar' should use USER as the owner of members when
     creating archives, instead of the user associated with the source
     file.  USER is first decoded as a user symbolic name, but if this
     interpretation fails, it has to be a decimal numeric user ID.

     There is no value indicating a missing number, and `0' usually
     means `root'.  Some people like to force `0' as the value to offer
     in their distributions for the owner of files, because the `root'
     user is anonymous anyway, so that might as well be the owner of
     anonymous archives.

     Tells `tar' to create an archive that is compatible with Unix V7

     Instructs `tar' to create a POSIX compliant `tar' archive.

     Synonymous with specifying both --preserve-permissions' and

     (See --same-order; *note Reading::..)

     When `tar' is extracting an archive, it normally subtracts the
     users' umask from the permissions specified in the archive and
     uses that number as the permissions to create the destination
     file.  Specifying this option instructs `tar' that it should use
     the permissions directly from the archive.  *Note Writing::.

     Specifies that `tar' should reblock its input, for reading from
     pipes on systems with buggy implementations.  *Note Reading::.

     Instructs `tar' to use SIZE bytes per record when accessing the

     Similar to the --unlink-first option, removing existing
     directory hierarchies before extracting directories of the same
     name from the archive.  *Note Writing::.

     Directs `tar' to remove the source file from the file system after
     appending it to an archive.

     Notifies `tar' that is should use CMD to communicate with remote

     This option is an optimization for `tar' when running on machines
     with small amounts of memory.  It informs `tar' that the list of
     file arguments has already been sorted to match the order of files
     in the archive.  *Note Reading::.

     When extracting an archive, `tar' will attempt to preserve the
     owner specified in the `tar' archive with this option present.

     (See --preserve-permissions; *note Writing::..)

     Instructs `tar' to mention directories its skipping over when
     operating on a `tar' archive.

     Invokes a GNU extension when adding files to an archive that
     handles sparse files efficiently.

     This option affects extraction only; `tar' will skip extracting
     files in the archive until it finds one that matches NAME.  *Note

     Alters the suffix `tar' uses when backing up files from the default

     Specifies the length of tapes that `tar' is writing as being
     NUM x 1024 bytes long.

     During extraction, `tar' will extract files to stdout rather than
     to the file system.  *Note Writing::.

     Displays the total number of bytes written after creating an

     Sets the modification time of extracted files to the extraction
     time, rather than the modification time stored in the archive.
     *Note Writing::.

     (See --compress.)

     (See --gzip.)

     Direct `tar' to remove the corresponding file from the file system
     before extracting it from the archive.  *Note Writing::.

     Instruct `tar' to access the archive through PROG, which is
     presumed to be a compression program of some sort.

     Be more verbose about the operation.
     This option can be specified multiple times (for some operations)
     to increase the amount of information displayed.

     Verify that the archive was correctly written.

     `tar' will print an informational message about what version it is
     and a copyright message, some credits, and then exit.

     Used in conjunction with --multi-volume'.  `tar' will keep track
     of which volume of a multi-volume archive its working in FILE.


Create a tar and zip the file (using the create function)

  tar -czvf MyArchive Source_file 
  tar --create --gzip --verbose --file=MyArchive.gz Source_file

Extract the zip file created above:

  tar -xzvf MyArchive Destination_file 
  tar --extract --gunzip --verbose --file=MyArchive.gz Destination_file

Extract a file, autodetecting the format, in this case an xz archive:

  tar -xf some.tar.xz
  tar --extract --file=some.tar.xz

Create a tar in zip format with the file named as todays date/time:

tar czvf my_backup.$(date +%Y%m%d-%H%M%S).tgz /users/simon

A simple shell script for the above:

tar czvf $1.$(date +%Y%m%d-%H%M%S).tgz $1
exit $?

Save the script as 'arc', use chmod to make it executable and then run it passing a single file or foldername:

chmod 700 arc
./arc /users/simon


Always tar -t before tar -x to check if the archive contents have been placed inside one subdirectory or will just spill all over the current directory.

The -C feature does not work like historical gnutar programs, and is probably untrustworthy.

The -A command should work to join an arbitrary number of gnutar archives together, but it does not; attempting to do so leaves the end-of-archive blocks in place for the second and subsequent archives.

The gnutar file format is a semi fixed width field format, and the field for device numbers were designed for 16 bit (8 major, 8 minor) and can not absorb our 32 bit (8 major, 16+8 minor) numbers.

"To disarm the bomb simply enter a valid tar command on your first try. No Googling" ~ XKCD


gzip - Compress or decompress named file(s)
sum - Print a checksum for a file
unshar - Unpack shell archive scripts
xz - Compress or decompress .xz and .lzma files
zip - Package and compress (archive) files.
Equivalent Windows command: ZIP - compress files

© Copyright SS64.com 1999-2016
Some rights reserved