Home / Blog / Post
Compressing A Directory On Linux
Added on 22nd January 2018 in Snippet

Creating An Archive

A simple way is using the TAR command which using the following sytnax

tar -zcvf archive-name.tar.gz directory-name

tar: The Program we are using (Flags) -z: Compress archive using gzip program -c: Create archive -v: Verbose i.e display progress while creating archive -f: Destination File Name

An Example of this would be the following

$ tar -zcvf my-archive.tar.gz /home/cshaw/project

Excluding a Directory

When creating the archive you may want to exclude certain directories, for instance .git

$ tar -zcvf my-archive.tar.gz --exclude=".git" /home/cshaw/project

Extracting An Archive

The syntax is similar to extract the active. The main difference is we change the flag -c (create) to -x (extract)

$ tar -zxvf my-archive.tar.gz /home/chris/project

Hi there, I am christopher shaw, a software developer form South Yorkshire, England.

I love tinkering with all things tech, and opened this website as a web presence for myself and a place to keep my notes and snippets. Hopefully you will find something here to help

Christopher Shaw