To tar all .cc and .h files into a tar file named foo.tgz use:
tar cvzf foo.tgz *.cc *.h
This creates (c) a compressed (z) tar file named foo.tgz (f) and shows the files being stored into the tar file (v). The .tgz suffix is a convention for gzipped tar files, it’s useful to use the convention since you’ll know to use z to restore/extract.
It’s often more useful to tar a directory (which tars all files and subdirectories recursively unless you specify otherwise). The nice part about tarring a directory is that it is untarred as a directory rather than as individual files.
tar cvzf foo.tgz cps100
will tar the directory cps100 (and its files/subdirectories) into a tar file named foo.tgz.
To see a tar file’s table of contents use:
tar tzf foo.tgz
To extract the contents of a tar file use:
tar xvzf foo.tgz
This untars/extracts (x) into the directory from which the command is invoked, and prints the files being extracted (v).
If you want to untar into a specified directory, change into that directory and then use tar. For example, to untar into a directory named newdir:
mkdir newdir
cd newdir
tar xvzf ../foo.tgz
You can extract only one (or several) files if you know the name of the file. For example, to extract the file named anagram.cc from the tarfile foo.tgz:
tar xvzf foo.tgz anagram.cc