89 lines
4.9 KiB
HTML
89 lines
4.9 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
|
<!Converted with LaTeX2HTML 95.1 (Fri Jan 20 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
|
<HEAD>
|
|
<TITLE>4.5.1 Using tar</TITLE>
|
|
</HEAD>
|
|
<BODY>
|
|
<meta name="description" value="4.5.1 Using tar">
|
|
<meta name="keywords" value="gs">
|
|
<meta name="resource-type" value="document">
|
|
<meta name="distribution" value="global">
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html3974 HREF="node174.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A> <A NAME=tex2html3972 HREF="node172.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A> <A NAME=tex2html3966 HREF="node172.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <A NAME=tex2html3976 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif"></A> <A NAME=tex2html3977 HREF="node250.html"><IMG ALIGN=BOTTOM ALT="index" SRC="index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html3975 HREF="node174.html">4.5.2 gzip and compress</A>
|
|
<B>Up:</B> <A NAME=tex2html3973 HREF="node172.html">4.5 Archiving and Compressing </A>
|
|
<B> Previous:</B> <A NAME=tex2html3967 HREF="node172.html">4.5 Archiving and Compressing </A>
|
|
<BR> <HR> <P>
|
|
<H2><A NAME=SECTION00651000000000000000>4.5.1 Using tar</A></H2>
|
|
<P>
|
|
<A NAME=4665> </A>
|
|
The <tt>tar</tt> command is most often used to archive files.
|
|
<P>
|
|
The format of the <tt>tar</tt> command is
|
|
<P><TT> tar <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img254.gif"> <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img255.gif"> <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img256.gif"> ...<IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img257.gif"> <P></TT>
|
|
where <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img258.gif"> is the list of commands and options for <tt>tar</tt>,
|
|
and <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img259.gif"> through <IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img260.gif"> is the list of files to
|
|
add or extract from the archive.
|
|
<P>
|
|
For example, the command
|
|
<P><TT> # <em>tar cvf backup.tar /etc</em>
|
|
<P></TT>
|
|
would pack all of the files in <tt>/etc</tt> into the tar archive
|
|
<tt>backup.tar</tt>. The first argument to <tt>tar</tt>---``<tt>cvf</tt>''---is
|
|
the <tt>tar</tt> ``command''. ``<tt>c</tt>'' tells <tt>tar</tt> to
|
|
create a new archive file. The ``<tt>v</tt>'' option forces <tt>tar</tt>
|
|
into verbose mode---printing each filename as it is archived. The
|
|
``<tt>f</tt>'' option tells <tt>tar</tt> that the next
|
|
argument---<tt>backup.tar</tt>---is the name of the archive to create. The
|
|
rest of the arguments to <tt>tar</tt> are the file and directory names to
|
|
add to the archive.
|
|
<P>
|
|
The command
|
|
<P><TT> # <em>tar xvf backup.tar</em>
|
|
<P></TT>
|
|
will extract the tar file <tt>backup.tar</tt> in the current directory.
|
|
This can sometimes be dangerous---when extracting files from a tar file,
|
|
old files are overwritten.
|
|
<P>
|
|
Furthermore, before extracting tar files
|
|
it is important to know where the files should be unpacked. For example,
|
|
let's say you archived the following files: <tt>/etc/hosts</tt>,
|
|
<tt>/etc/group</tt>, and <tt>/etc/passwd</tt>. If you use the command
|
|
<P><TT> # <em>tar cvf backup.tar /etc/hosts /etc/group /etc/passwd</em>
|
|
<P></TT>
|
|
the directory name <tt>/etc/</tt> is added to the beginning of
|
|
each filename. In order to extract the files to the correct
|
|
location, you would need to use the following commands:
|
|
<P><TT> # <em>cd /</em> <BR>
|
|
# <em>tar xvf backup.tar</em>
|
|
<P></TT>
|
|
because files are extracted with the pathname saved in the archive
|
|
file.
|
|
<P>
|
|
If, however, you archived the files with the command
|
|
<P><TT> # <em>cd /etc</em> <BR>
|
|
# <em>tar cvf hosts group passwd</em>
|
|
<P></TT>
|
|
the directory name is not saved in the archive file. Therefore,
|
|
you would need to ``<tt>cd /etc</tt>'' before extracting the files.
|
|
As you can see, how the tar file is created makes a large difference
|
|
in where you extract it. The command
|
|
<P><TT> # <em>tar tvf backup.tar</em>
|
|
<P></TT>
|
|
may be used to display an ``index'' of the tar file before unpacking
|
|
it. In this way you can see what directory the filenames in the archive
|
|
are stored relative to, and can extract the archive from the correct
|
|
location.
|
|
<P>
|
|
<BR> <HR><A NAME=tex2html3974 HREF="node174.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A> <A NAME=tex2html3972 HREF="node172.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A> <A NAME=tex2html3966 HREF="node172.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <A NAME=tex2html3976 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif"></A> <A NAME=tex2html3977 HREF="node250.html"><IMG ALIGN=BOTTOM ALT="index" SRC="index_motif.gif"></A> <BR>
|
|
<B> Next:</B> <A NAME=tex2html3975 HREF="node174.html">4.5.2 gzip and compress</A>
|
|
<B>Up:</B> <A NAME=tex2html3973 HREF="node172.html">4.5 Archiving and Compressing </A>
|
|
<B> Previous:</B> <A NAME=tex2html3967 HREF="node172.html">4.5 Archiving and Compressing </A>
|
|
<BR> <HR> <P>
|
|
<BR> <HR>
|
|
<P><ADDRESS>
|
|
<I>Matt Welsh <BR>
|
|
mdw@sunsite.unc.edu</I>
|
|
</ADDRESS>
|
|
</BODY>
|