Buy @ Amazon

tar command (with compress option)


Reading through the Unix's man or manual for a command description may be a little pain but with repeated practice you get used to it. In this blog I mix the manual's content and add my own example which might be of frequent use in general.

SYNOPSIS

tar [-] A --catenate --concatenate |
           c --create |
           d --diff --compare |
              --delete |
           r --append |
           t --list |
             --test-label |
           u --update |
           x --extract
              --get [options] [pathname ...]

DESCRIPTION

Tar stores and extracts files from a tape or disk archive. The first argument to tar should be a function; either one of the letters Acdrtux, or one of the long function names.

Some options take a parameter; with the single-letter form these must be given as separate arguments. With the long form, they may be given by appending = value to the option.

FUNCTION LETTERS

-A, --catenate, --concatenate
     append tar files to an archive
-c, --create
     create a new archive
-d, --diff, --compare
     find differences between archive and file system
--delete
     delete from the archive (not on mag tapes!)
-r, --append
     append files to the end of an archive
-t, --list
     list the contents of an archive
--test-label
     test the archive volume label and exit
-u, --update
     only append files newer than copy in archive
-x, --extract, --get
     extract files from an archive

OTHER OPTIONS

-a, --auto-compress
     use archive suffix to determine the compression program
--add-file=FILE
     add given FILE to the archive (useful if its name starts with a dash)
--atime-preserve
     preserve access times on dumped files, either by restoring the times
--no-auto-compress
     do not use archive suffix to determine the compression program
-C, --directory DIR
     change to directory DIR
--checkpoint
     display progress messages every NUMBERth record (default 10)
--exclude-vcs
     exclude version control system directories
-f, --file ARCHIVE
     use archive file or device ARCHIVE
--force-local
     archive file is local even if it has a colon
-h, --dereference
     follow symlinks; archive and dump the files they point to
--hard-dereference
     follow hard links; archive and dump the files they refer to
--ignore-case
     ignore case
--no-ignore-case
     case sensitive matching (default)
-k, --keep-old-files
     don't replace existing files when extracting
--keep-newer-files
     don't replace existing files that are newer than their archive copies
-X, --exclude-from FILE
     exclude patterns listed in FILE
-z, --gzip, --gunzip --ungzip
     filter the archive through gzip
-Z, --compress, --uncompress
     filter the archive through compress

EXAMPLES

Create .tar archive from files foo and bar
     $ tar -cf archive.tar foo bar
List all files in .tar archive verbosely
     $ tar -tvf archive.tar
Extract all files from .tar archive
     $ tar -xf archive.tar
Create zipped .tar archive from /home/karthik/myprojects
     $ tar -zcvf myprojects.tar.gz /home/karthik/myprojects
Unzip and Restore an archive myprojects.tar.gz to say current directory
     $ tar -zxvf myprojects.tar.gz
Unzip and Restore an archive myprojects.tar.gz to an existing directory say /temp
     $ tar -zxvf myprojects.tar.gz /temp