Once in a while I need to compress a bunch of files and directories into a single, easy to transport file that can be later de-compressed as needed.  Sometimes I do this for backup purposes and sometimes just to move websites to new hosts.  What’s nice about the tar command in linux is that it allows you to compress entire directories and all sub directories below it recursively.

To compress a directory, run this tar command:

tar cvzf <output file> <input directory>

just replace <output file> and <input file> respectively and you’ll have yourself a compressed tar file after it’s done executing.

To de-compress a tar file (untar), run this command:

tar xvfz <file name>

Again, if you tared up a directory, vs just a set of files, the untar command will decompress the directory itself retaining the original file structure, nice.

If you just want to look at the contents of a tar file without decompressing anything:

tar tzf <file name>

If you want a little more information on the Tar command, check out Duke’s tar guide.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Reddit
  • StumbleUpon

Leave a Reply