Guide to create and extract Tar and Zip Archives

Category : Linux/ Unix

Looking for CLI commands to create tar and zip archives so that you can transfer a couple of files and folders to a different machine with ease? The tar is most widely used command to create compressed archive files and that can be moved easily from one disk to another disk or machine to machine. The same purpose is served by zip. Zip also creates a compressed archive file.

Create tar archive

We will create a tarball for a folder named ‘data’.

Command – tar -cvf backup.tar data/

  • c – Creates a new .tar archive file.
  • v – Verbosely show the .tar file progress.
  • f – File name type of the archive file.

create tar

Extract tar archive

We will extract a backup.tar archive

Command – tar -xvf backup.tar

  • x – Extracts tar archive file.
  • v – Verbosely show the .tar file progress.
  • f – File name type of the archive file.

extract tar

Create zip archive

We will create a zip archive for a folder named ‘data’.

Command – zip -r4 backup.zip data/

  • r – the recursive flag to include all files and subfolders
  • 4 – Level of compression to use for the zip archive

create zip

Extract zip archive

We will extract a zip archive named backup.zip

Command – unzip backup.zip

extract zip

 

With this, we finish basic commands that help us to work with tar and zip archives.