[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedFebruary 21, 2023

How to Compress and Extract Files and Directories in Linux Using gzip and bzip2

How to Compress and Extract Files and Directories in Linux Using gzip and bzip2

The post explains provides basic commands to compress files and folders in Linux OS. To compress a file or folder, gzip and bzip2 are two very popular tools.

 

Gzip Compression

To compress a file:

# gzip file1

A file by name file1.gz will be created in current directory replacing file1. You can compress multiple files in one go by just specifying their names, separated by spaces. For example:

# gzip file1 file2 file3

To expand a gzip compressed file in current directory:

# gunzip file1.gz

To compress a directory, you can create a tar and compress it.

# tar -czvf name-of-archive.tar.gz /path/to/directory

To compress multiple directories in one file:

# tar -czvf name-of-archive.tar.gz /path/directory1 /path/directory2

To extract the a “tar and compressed” directory in your current directory,

# tar -xzvf name-of-archive.tar.gz

To extract the a “tar and compressed” directory in a particular directory,

# tar -xzvf name-of-archive.tar.gz -C /path/to/directory

 

Bzip2 compression

To compress a file:

# bzip2 file1

A file by name file1.bz2 will be created in current directory replacing file1. Similar to gzip you can compress multiple files in one go. For example

# bzip2 file1 file2 file3

To expand a file in current directory:

# bunzip2 file1.bz2

To compress a directory, you can create a tar and compress it.

# tar -cjvf name-of-archive.tar.bz2 /path/to/directory

To compress multiple directories in one file:

# tar -cjvf name-of-archive.tar.bz2 /path/directory1 /path/directory2

To extract the a “tar and compressed” directory in your current directory,

# tar -xjvf name-of-archive.tar.bz2

To extract the a “tar and compressed” directory in a particular directory,

# tar -xjvf name-of-archive.tar.bz2 -C /path/to/directory

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM