~terry
Thu, Jan 20, 2000 (09:06)
seed
The "tar" command stands for tape archive.
This command is used to create new archives, list files in existing
archives, and extract files from archives.
The tar command can be used to write archives directly to tape devices, or
you can use it to create archive files on disk. In many cases, tar
archives are created on disk so it's easier to transport them across
networks, such as the Internet.
Note - the tar command does not compress files. Use the compress command
to compress the tar archive after you've created it.
~terry
Thu, Jan 20, 2000 (09:07)
#1
tar cvf /dev/rct0 /home
This command writes a tar archive to the tape device /dev/rct0. It copies
the files in the /home directory, and all subdirectories of /home to the
tape device.
tar cvf /dev/fd0 /home/fred
This command writes a tar archive to the diskette device /dev/fd0. It
copies the files in the /home/fred directory, and all subdirectories of
/home/fred to the diskette.
tar cvf /tmp/home.tar /home
This command creates a tar archive named /tmp/home.tar. The tar command
copies the files in the /home directory, and all subdirectories of /home.
tar cvf /tmp/home.tar /home
compress /tmp/home.tar
This example shows two commands issued in sequence. The first command
creates a tar archive named /tmp/home.tar. The second command compresses
the tar archive, and replaces it with a new compressed tar archive, named
/tmp/home.tar.Z. See the compress command for more details.
~terry
Thu, Jan 20, 2000 (09:09)
#2
Tarball is a jargon term for a tar archive, suggesting "a bunch of files
stuck together in a ball of tar."
~terry
Thu, Jan 20, 2000 (09:10)
#3
TAR
Tape ARchive utility
To archive (compress) files:
tar -cvf [tar-file] [files-to-archive]
To extract files:
tar -xvf [tar-file]
SWITCH:
-c Compress
-x Extract
-v Verbose mode on
-f Work with local disk file instead of tape drive
Compressing a directory,
tar cvf - | gzip > directory.tgz
Quick de-compression of a compressed, tar file
gzip -cd file.tgz | tar xvf -
~terry
Thu, Oct 11, 2001 (12:15)
#4
tar -cf - files | compress > tarfile
one line that compreses tar files.
~terry
Sun, Sep 15, 2002 (19:17)
#5
Command tar
Description The "tar" command stands for tape archive.
This command is used to create new archives, list files in existing archives, and extract files from archives.
The tar command can be used to write archives directly to tape devices, or you can use it to create archive files on disk. In many cases, tar archives are created on disk so it's easier to transport them across networks, such as the Internet.
Note - the tar command does not compress files. Use the compress command to compress the tar archive after you've created it.
Examples tar cvf /dev/rct0 /home
This command writes a tar archive to the tape device /dev/rct0. It copies the files in the /home directory, and all subdirectories of /home to the tape device.
tar cvf /dev/fd0 /home/fred
This command writes a tar archive to the diskette device /dev/fd0. It copies the files in the /home/fred directory, and all subdirectories of /home/fred to the diskette.
tar cvf /tmp/home.tar /home
This command creates a tar archive named /tmp/home.tar. The tar command copies the files in the /home directory, and all subdirectories of /home.
tar cvf /tmp/home.tar /home
compress /tmp/home.tar
This example shows two commands issued in sequence. The first command creates a tar archive named /tmp/home.tar. The second command compresses the tar archive, and replaces it with a new compressed tar archive, named /tmp/home.tar.Z. See the compress command for more details.
~terry
Tue, Sep 17, 2002 (11:17)
#6
What do I do with a .tar file? A .tar.gz file?
TAR is a UNIX command that allows you to create a single archive file
containing many files. Such archiving allows you to maintain directory
relationships and facilitates transferring complex programs with many
separate but integrated parts that must have their relationships
preserved. TAR has a plethora of options that allow you to do archiving
and unpacking in many ways. However, for the purpose of unpacking CGI
applications, the commands will be fairly simple.
The files on our site are now GZipped (.tar.gz). That just means we
compressed them with GNU GZip. Your browser should be able to download it
and recognize the file without any problems.
Unpacking on UNIX
tar xvfpz file_name.tar.gz
or
tar xvfz file_name.tar (if "p" won't work)
TAR will go through the archive file and extract each individual directory
and file, expanding them into their appropriate places beneath the current
directory. The "xvfzp" letters in the TAR command above are parameters
that instruct the program to decompress the files and then extract the
files and directories out of the ".tar" file.
If you are not using GNU TAR, you will need to add a step to the process:
gunzip file_name.tar.gz (removes the .gz)
tar xvfp file_name.tar
or
tar xvf file_name.tar (if "p" won't work)
Tar Extraction Parameters:
Parameter Description
x Tells tar to extract the files.
v Tells tar to output information about the status of its extraction while
it is performing the work.
f Informs tar to use the ".tar" filename as the source of the files to be
extracted. The reason the "f" parameter has to be used is that tar, by
default, archives files and directories to a tape drive. TAR is actually
short for "[T]ape [AR]chive".
p Notes that the original permissions should be maintained.
z Instructs TAR to decompress a file first.
Unpacking on Windows and Mac
If you are not using a UNIX-based web server, or donIf you use a
Windows-based text editor however, you need to be very careful about
accidentally inserting platform-specific, invisible control characters
(like carriage return characters) into the files. If you are editing the
files on a Windows box, this is often a problem because Windows programs
are well-known for their desire to insert Windows-only characters into
files.
You will know that invisible characters have infected the files if you get
a 500 Server Error when trying to run the application from the web, and
error messages like the following if you run the application from the
command line:
Illegal character \015 (carriage return) at app_name.cgi line 2.
or
Can't find string terminator " [some text here]" anywhere before EOF
Generally, this problem can be solved either by choosing a text editor
that does not insert the characters or by setting your FTP program to
upload edited files to the web server machine using "ASCII mode" instead
of "BINARY mode". You should be able to set the FTP program to transfer in
ASCII mode using the program's preferences. We recommend using WS_FTP that
has this functionality and is available at http://www.shareware.com/.
However, if the files have already been sent over to a UNIX-based web
server, you can strip bad characters using:
find . -type f -exec perl -pi -e 's|\cM||' {} \;
~terry
Sun, Oct 13, 2002 (20:48)
#7
How many times have you encountered tar files that include a full path to every file
instead of the relative paths (which make extracting the files into your chosen directory
easier)? The paths included in the tar file depend, of course, on the commands originally
used to create the tar file. Tar files that include full paths can be troublesome to use
because they sometimes "want" to be extracted into a file system that doesn't have enough
free space to accommodate them. Most of us don't want to spend time extracting portions
of the files and moving them to the correct location. The reason for using a tar file in
the first place is, after all, so that you get a collection of files all with the correct
relationship to each other and ready to be replicated anywhere. Since tar files have a
special format, processing them so that the paths within the files will be removed isn't
an easy task. What I normally do when I have to deal with one of these files is create a
symbolic link that looks like the intended directory but diverts the extraction to the
location where I want the files. For example, let's say that I am given a tar file with
contents such as this:
$ tar tvf eg.tar
-rwxr-xr-x 1111/14 514 Jul 12 09:31 2001 /opt/bin/wiglet/pics/coreadm
-rw-r--r-- 1111/14 17408 Aug 17 16:39 2001 /opt/bin/wiglet/pics/eg.tar
-rwxr-xr-x 1111/14 4199 Jul 12 09:10 2001 /opt/bin/wiglet/pics/eg1
-rwxr-xr-x 1111/14 22208 Jul 12 10:53 2001 /opt/bin/wiglet/pics/eg10
-rwxr-xr-x 1111/14 172123 Jul 12 10:54 2001 /opt/bin/wiglet/pics/eg11
-rwxr-xr-x 1111/14 762392 Jul 12 10:59 2001 /opt/bin/wiglet/pics/eg12
-rwxr-xr-x 1111/14 485164 Jul 12 09:13 2001 /opt/bin/wiglet/pics/eg2
-rwxr-xr-x 1111/14 943145 Jul 12 09:21 2001 /opt/bin/wiglet/pics/eg3
-rwxr-xr-x 1111/14 843267 Jul 12 09:28 2001 /opt/bin/wiglet/pics/eg4
-rwxr-xr-x 1111/14 383048 Jul 12 10:29 2001 /opt/bin/wiglet/pics/eg5
-rwxr-xr-x 1111/14 38457 Jul 12 10:33 2001 /opt/bin/wiglet/pics/eg6
-rwxr-xr-x 1111/14 832156 Jul 12 10:35 2001 /opt/bin/wiglet/pics/eg7
-rwxr-xr-x 1111/14 102368 Jul 12 10:36 2001 /opt/bin/wiglet/pics/eg8
-rwxr-xr-x 1111/14 5555153 Jul 12 10:52 2001 /opt/bin/wiglet/pics/eg9
-rwxr--r-- 1111/14 881959 Jul 12 09:52 2001 /opt/bin/wiglet/apps/powertool
If I don't have room in /opt for these files and really want them in /usr/local, I can't
simply untar the tar file. Instead, I create a symbolic link for the wiglet directory like
this:
# cd /opt/bin
# mkdir /usr/local/wiglet
# ln -s /usr/local/wiglet .
Afterwards, I can untar my file and the contents land in /usr/local/wiglet instead of
/opt/bin/wiglet. When you create a tar file, the directory structure will reflect the
location from which the tar file was created unless, of course, you specify the full path
in your command. You can be inside the /opt/bin/wiglet directory and type:
# tar cvf wiglet.tar /opt/bin/wiglet
and you'll end up with a tar file with full paths included. Typing this instead:
# tar cvf wiglet.tar .
will create a tar file that includes paths starting with "./". The command:
# tar cvf wiglet.tar *
will omit the harmless "./".
If the directory specified in the ill-behaved tar file already exists on your system,
workarounds are that much more of problem. If you can, move the current same-named
directory out of the way temporarily, create the symlink, extract the files, and then put
everything back the way it was.
It's probably possible to write a program that would replace the paths in a tar file with
paths more to your liking. However, such a program would have to consider the checksums
built into tar. A careless replacement would probably yield a file that could not be read
-- at least not by tar.
If you can't move the current directory because it's in use, another option is to extract
the tar file on another system and tar it up correctly (i.e., with relative paths). Then,
you can use the file on the intended system without having to go through any special
contortions
from
http://www.itworld.com/nl/unix_sys_adm/08222001/