What is Relay

gzip (GNU Zip) is a popular compression tool in Linux (and Unix-like systems) used to reduce the size of files. It is primarily used for file compression, and it’s known for its efficiency and fast compression speed. It only compresses individual files, not directories, but it is commonly used in combination with other tools like tar to archive and compress entire directories.

Key Features of gzip:

  • File Compression: It compresses individual files into .gz files.
  • Lossless Compression: The original file can be fully restored after decompression (no data loss).
  • Speed: gzip is fast, making it ideal for quickly reducing file sizes.
  • Widely Used: Commonly used in Linux for backups, transferring large files, and software distribution.

 

Creating a compressed archive using tar and gzip:

  • c: Create a new archive
  • z: Compress using gzip
  • v: Verbose (lists files being archived)
  • f: Specify the file name (archive_name.tar.gz)
Extracting a compressed tar.gz archive:
  • x: Extract the archive
  • z: Decompress using gzip
  • v: Verbose (lists files being extracted)
  • f: Specify the archive file nam

Advantages of gzip:

  • Speed: It offers fast compression and decompression speeds, making it useful for handling large files quickly.
  • Efficiency: gzip provides good compression ratios, reducing file size effectively.
  • Widely Supported: It is compatible across most Unix-like systems, including Linux and macOS.

Disadvantages of gzip:

  • Single File Compression: gzip works on individual files, so if you need to compress multiple files or entire directories, you must combine it with tools like tar.
  • No Built-in Encryption: Unlike some other compression formats (e.g., .zip), gzip does not have built-in support for encryption or password protection.

Common Extensions Associated with gzip:

  • .gz: The most common extension used for files compressed with gzip.
  • .tar.gz or .tgz: A compressed archive created by using tar to bundle files, followed by gzip compression.

Summary:

gzip is a file compression tool in Linux that is primarily used to reduce the size of individual files. It is fast and efficient but doesn’t handle directories on its own. It is often used in conjunction with tar to archive and compress multiple files or directories.

 

Notes- Only for Use Gzip file type not Use directory

Linux create tar.gz file with tar command

Linux create tar.gz file with tar command
tar -czvf filename.tar.gz /path/to/dir1
tar -czvf filename.tar.gz /path/to/dir1 dir2 file1 file2

-c is creating and archive.

-z is using gzip compression.

-v is providing details of the files that have been archived.

-f is creating an archive with the name ‘logs_archive.tar.gz’ as supplied in the command above.

 

How to extract a tar.gz compressed archive on Linux
tar -xvf file.tar.gz
tar -xzvf file.tar.gz
tar -xzvf projects.tar.gz

-x is extracting and archive.

-z specifies that the archive is gzip.

-v is providing details of the files that have been archived.

-f is extracting from the archive named ‘logs_archive.tar.gz

 

How to view the contents of an archive
tar -tvf logs_archive.tar.gz

 

File.gz File View commnd

zcat file.gz

 

Zip file View without extarct Commnd

zipinfo file.zip

Use the Most Common zip Command Options

The following are the most common zip command options:

 

How to create multiplefile touch commend ?
touch filename{1..10}.txt

How to create tar file ?
tar cvf <filename>.tar <filename> then enter

How to create tar file untar ?
tar xvf <filename>.tar <filename> then enter
tar –xvzf <filename>.tar <filename> then enter

How to create compress reduce size tar file ?
tar cjf <filename>.tar.gz cvf <filename> then enter

How to create gzip ?
gzip <filename>

 

How to create gzip extarct ?
gunzip <filename>
zcat <filename>

How to create bzip2 ?
bzip2 <filename>

How to create bzip2 extarct ?
bunzip2 <filename>

 

How to view file size check ?
du -sh <filename>

Only Zip File

The Zip command in Linux is a powerful utility that compresses files and directories into a single archive file using the .zip format. Compressing files reduces the size and helps to pack multiple files together for faster data transfer or storage. Many operating systems, such as Windows, macOS, Linux, and Unix support the Zip format, allowing you to pack and extract files across major platforms.

 

The zip command in Linux is used to archive and compress files into a single .zip file. It combines multiple files and directories into one file while compressing them to reduce the overall size. zip is widely used across different platforms (including Windows, Linux, and macOS), making it a convenient choice for cross-platform file sharing.

Key Features of the zip Command:

  • Compression and Archiving: zip compresses files and archives them into a .zip file, making it convenient for file storage and transfer.
  • Cross-Platform Compatibility: .zip files can be opened on most operating systems, including Linux, Windows, and macOS, using native tools (like WinRAR on Windows or the built-in unzip command on Linux).
  • File Selection: You can compress individual files, multiple files, or entire directories.

ommon zip Command Options

The following are the most common zip command options:

OptionDescription
-rRecursively compress directories and their contents.
-jJunk (omit) directory names from the Zip archive.
-mMove the specified files into the Zip archive (delete files after zipping).
-uUpdate existing entries in the Zip archive with newer versions.
-dDelete entries from the Zip archive.
-xExclude specific files or patterns from being zipped.
-qQuiet mode, suppress output messages for less verbosity.
-vVerbose mode, display detailed output during the compression process.
-9Use the best compression method to maximize file size reduction.
-eEncrypt the Zip archive with a password for added security.

Compress the dir directory and all its contents including
sub-directories into archive.zip.

zip -r archive.zip dir/

 

Delete specific files, such as file1.txt from the archive.zip
zip -d archive.zip file1.txt