How to compress a whole Lunux/Unix directory into a tarball file

It is extremely easy to compress files and directories in Linux/ Unix using the tar command.  This command is used to create create .tar.gz or .tgz archive files; the so called “tarballs.”  You can do a lot of tasks with this command. It has a lot of options. Man page man tar or help file tar –help always come in handy. The command is useful to create a single archive of a whole project with many files and directories, send it to somebody, download it, etc.

Tar command can be also used on a remote server via ssh. When executed it creates and compresses the archive.  It uses the following syntax :

tar -zcvf archive-name.tar.gz /path/to/mydirectory

This command works recursively, i.e. compresses the content of every directory inside mydirecory.

Here are what the options passed to the command mean:

  1. z   Compress the archive using gzip
  2. c    Create the archive
  3. v    Verbose mode, display the results on the go
  4. f     Gives you the opportunity to choose filename of the archive

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *