Zipping a File in Bash

Get to know the commands to zip files in bash.

tar

Definition:

Tar — short for tape archive is used to convert files in tar format and archive them in a file. An archive format is widely used to store multiple files and transfer them to another system. They can be extracted, once recieved on the second end. We use Tar command for all these purposes.

Syntax:

tar [option(s)] [archive_file_name] [file_name(s)]

Options:

The tar command is one of those rare commands which requires to specify at least one option in order to work properly. Here are a few options commonly used with tar command, you can use them individually or combine them in a single tar command.

Option Meaning
-c Creates an archive
-x Extracts an archive
-f Create archive with the given name
-t Display the files in archive
-z Creates archive with gzip
-r Update/Add the archive file with new files
-v Verbose

Example:

  1. Archive three files into a single tar file and name it “my_files.tar”

Get hands-on with 1200+ tech skills courses.