Partha Talukdar
By Partha Talukdar

How to compress and uncompress files in linux.

How to compress and uncompress files in linux.

Compressing , Uncompressing Files In Linux?

The most commonly used commands in linux are tar, gzip and gunzip for compressing and uncompressing files in linux.

Tar vs Gzip

The tar command is used to compress a group of files into an archive. The command is also used to extract or modify tar archives as well.

The tar command does not necessarily compresses the files in the archive it just groups them into a single file. To achieve compression and reduce disk usage on your linux systems the gzip option can be used with tar.

Basic Syntax For Tar?

1
2
3
4
5
tar [options] [archive-file] [file or directory to be archived]



Options For Tar?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-c : Creates archive

-x : Extracts the archive

-f : creates archive with given filename

-t : displays or lists files in archived file

-u : archives and adds to an existing archive file

-v : Displays verbose information

-A : Concatenates the archive files

-z : compresses the tar file using gzip

-j : compresses the tar file using bzip2

-W : Verifies an archive file

-r : updates or adds file or directory in already existing .tar file



Example Usage Of Tar and Gzip:

  • Extract an archive:
1
2
3
4
5
$tar xfv archive.tar



(Options: x = extract, f = file, v = verbose)

  • Create an archive with files or folder:
1
2
3
4
5
$tar cfv archive.tar file1 file2 file3



(Options: c = create)

  • Create compressed archives with tar using gzip:
1
2
3
4
5
tar cfzv archive.tar file1 file2 file3



(Options: z = compress with gzip)

  • Extract files from gzip tar Archive archive.tar.gz:
1
2
3
4
5
$tar xvzf archive.tar.gz



(Options: x = extract, f = file, v = verbose)

More Useful Resources:

Create Tar GZ File

Tar in linux

Tar Examples