<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[onecolumn,letterpaper,11pt]{article}

%===================================================================
\input{common_latex/common_latex_packages}
\input{common_latex/common_latex_definitions}
\input{common_latex/common_latex_help_format}
%===================================================================

\begin{document}

\begin{labcover}
\labtitle{Help Topic: Creating and Expanding Tar Files}
\vspace{0.1in}
\labdate{Spring 2020}
\vspace{0.1in}
\labauth{Michael Benjamin, mikerb@mit.edu}
\labauth{Department of Mechanical Engineering}
\labauth{MIT, Cambridge MA 02139}
\labline
\end{labcover}

\wikidoc{file=Help.CMDTar}
\wikidoc{auth=mikerb@mit.edu}

%====================================================================
\section*{Creating and Expanding Tar Files}
%====================================================================

\noindent
At times it is useful to pass around a whole directory (folder) as a
single file, for example, to email it to someone. There are a few ways
to do this. Here we discuss one of the oldest and most ubiquitous
forms for doing this, using the \cmd{tar} utility. This utility is
natively available in MacOS (in \var{/usr/bin/tar}), and Linux
(in \var{/bin/tar}).

\pskip
As with many command line utilities, you can find much more
information by just typing \var{"man tar"} on the command line. You'll
find there are a lot of options. We'll discuss a couple uses to ensure
you can \cmd{tar} a directory and "untar" a tar'ed file. To \cmd{tar}
a directory:

\vspace{0.15in}
\begin{consoleverb}
 $ ls
 my_directory/
 $ tar cvf my_directory.tar my_directory
 $ ls
 my_directory/  my_directory.tar
\end{consoleverb}
\vspace{0.15in}

\noindent
Note that (a) you should \cmd{tar} a directory when the target
directory is in your current working directory (don't do it while
inside the directory).  (b) the tar file is made without affecting the
directory itself, i.e., it does not replace the directory. (c) a
common convention is to call the tar file with the same name as the
directory, but just with the \var{.tar} suffix. Indeed you can call
the tar file anything you want, even excludig the suffix. But it's
very poor form to name a tar file with anything but a filename ending
in \var{.tar}.

\vspace{0.15in}
\noindent
If you took a look at the manpage for \cmd{tar}, you would see that the
above uses three separate command line option, \var{'-c'}, \var{'-v'},
\var{'-f'}. By convention, a few shortcuts are supported. The following
are all equivalent invocations:

\vspace{0.15in}
\begin{consoleverb}
 $ tar -c -v -f my_directory.tar my_directory
 $ tar -cvf my_directory.tar my_directory
 $ tar cvf my_directory.tar my_directory
\end{consoleverb}
\vspace{0.15in}

\vspace{0.15in}
\noindent
To untar the file:

\vspace{0.15in}
\begin{consoleverb}
 $ ls
 my_directory.tar
 $ tar xvf my_directory.tar my_directory
 $ ls
 my_directory/  my_directory.tar
\end{consoleverb}
\vspace{0.15in}

\noindent
Note that the only difference is the \var{-x} command line option
replaces the \var{'c'} option.

%===============================================================
\subsection*{Using Compression Along the Way}

Often, if you're tar'ing a folder to send or post, you want to make
this file as small as possible for the recipient's email box, or to
facilitate the speed of the download. If the directory contains source
code or other text files, the compression can be very effective. (If
the directory contains images or video, compression will have little
effect since images and video are already highly compressed).

\vspace{0.15in}
\noindent
To compress while tar'ing use:

\vspace{0.15in}
\begin{consoleverb}
 $ ls
 my_directory/
 $ tar cvfz my_directory.tgz my_directory
 $ ls
 my_directory/  my_directory.tgz
\end{consoleverb}
\vspace{0.15in}

\noindent
Note (a) the addition of the \var{'z'} command line options and (b) the
suffix has been changed to \var{.tgz}. A less-cool suffix is \var{.tar.gz}.

\vspace{0.15in}
\noindent
To untar the compressed file:

\vspace{0.15in}
\begin{consoleverb}
 $ ls
 my_directory.tgz
 $ tar xvfz my_directory.tgz my_directory
 $ ls
 my_directory/  my_directory.tgz
\end{consoleverb}
\vspace{0.15in}

\noindent
Note that using the correct file suffix is really important as a hint
to the user so they know what command line options are needed to
expand the file.  (Sending a compressed tar file with a \var{.tar}
suffix and not \var{.tgz} suffix will be really annoying to the
recipient!).

\vspace{0.35in}
\noindent
TIP: By the way, if you're wondering why, in my \cmd{ls} output above,
directories always in the \var{'/'} character, it is due to two
things. (1) I use the \var{-F} command line switch when
invoking \cmd{ls}, and (2) I make an alias for ls to make this my
default option. Using this visual cue can be super helpful and I
recommend trying/adopting it.
 
\end{document}

</pre></body></html>