tar is a tape archiving utility.
tar can be a convenient way to bundle up many files into one file for easy transportation.
tar is also used to unbundle files (and directories) from a tar file, and to list the contents in a tar file.
Options and Modes
tar works in three modes:
|creation||for creating or appending to a tar file|
|extraction||for extracting a file from a tar file|
|table of contents||for listing files in a tar file|
These modes are specified as options to tar:
||for creation mode|
||for extraction mode|
||for table-of-contents listing mode|
Other options then follow the mode. Two options that are used the most are the
||tells tar to use a file instead of a tape. You must tell tar what file you want to use.|
||tells tar to give you messages as to what it’s doing.|
How to Create a Tar File
If you have a directory you want to “tar”, use a command similar to the following:
tar -cvffile.tar dirname
Where file.tar is the name you want to give your tar file, and dirname is the name of the directory you want to tar.
Listing the Contents of a Tar File
To list in detail the contents of a tar file, use the following command:
Where file.tar is the name of your tar file.
If you just want a simple list, use the command:
How to Extract Files from a Tar File
If you want to extract one or a few files from a tar file, use a command similar to the following:
tar -xvffile.tar filenames
Where file.tar is the name of the tar file from which you would like to extract files, and filenames is a list of files you would like to extract. If you do not specify any file names, then tar extracts them all.
tar extracts files to your current working directory with the same
names that the files had when they were archived. Be careful not to overwrite already existing files with the same names.
Suggestion: Try extracting tar files from within a /tmp directory. This may help to avoid unwanted overwriting of files.
To read the man page entry for the
tar command, enter at your UNIX shell prompt: