Compress a directory in Linux

The tar command in Linux is used to compress or create an archive of a directory with .tar.gz or .tgz archive files,  they are also called “tarballs”.

Here tar is creating a archive named “archive-file-name.tar.gz” of “source-directory-name”.


-z = Compress the archive with gzip

-c = Creates a new .tar archive file

-v = Verbose, show .tar file progress

-f = Archive File name

Exclude particular directory or file 

To exclude a file or directory from being added in the archive use –exclude option

Compress multiple directories in single archive

You can add any no of directories or files you want to achive

How to Extract Archive

As you can see the only difference between creating an archive and extracting an archive is -x switch replace -c switch.