Linux gzexe Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the gzexe command in Linux to compress executable files, reducing their size and saving disk space. The lab covers the purpose and functionality of the gzexe command, how to compress executable files using gzexe, and how to decompress and execute the compressed files. This lab is part of the Backup and Compression skill set and provides practical examples to help you understand and apply the gzexe command effectively.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/CompressionandArchivingGroup(["`Compression and Archiving`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") linux/CompressionandArchivingGroup -.-> linux/tar("`Archiving`") linux/CompressionandArchivingGroup -.-> linux/zip("`Compressing`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/BasicFileOperationsGroup -.-> linux/chmod("`Permission Modifying`") linux/CompressionandArchivingGroup -.-> linux/gzip("`Gzip`") subgraph Lab Skills linux/echo -.-> lab-422713{{"`Linux gzexe Command with Practical Examples`"}} linux/tar -.-> lab-422713{{"`Linux gzexe Command with Practical Examples`"}} linux/zip -.-> lab-422713{{"`Linux gzexe Command with Practical Examples`"}} linux/ls -.-> lab-422713{{"`Linux gzexe Command with Practical Examples`"}} linux/chmod -.-> lab-422713{{"`Linux gzexe Command with Practical Examples`"}} linux/gzip -.-> lab-422713{{"`Linux gzexe Command with Practical Examples`"}} end

Understand the Purpose and Functionality of gzexe Command

In this step, you will learn about the purpose and functionality of the gzexe command in Linux. The gzexe command is used to compress executable files, reducing their size and saving disk space.

The gzexe command works by creating a compressed version of the executable file, which can then be executed directly without the need to decompress it first. This can be useful when you need to distribute or store executable files, as the compressed version will take up less space.

Let's start by checking the version of gzexe installed on your system:

gzexe --version

Example output:

gzexe (GNU gzip) 1.10
Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Jean-loup Gailly.

The gzexe command is part of the gzip package, which is a popular compression utility in Linux. It allows you to compress executable files without affecting their functionality.

Compress Executable Files Using gzexe

In this step, you will learn how to use the gzexe command to compress executable files on your Linux system.

First, let's create a sample executable file that we can use for the demonstration:

echo '#!/bin/bash
echo "This is a sample executable file."' > ~/project/sample_executable.sh
chmod +x ~/project/sample_executable.sh

Now, let's compress the executable file using the gzexe command:

gzexe ~/project/sample_executable.sh

The gzexe command will create a compressed version of the executable file, which will have the same name but with a .gz extension.

To verify the compression, let's check the file size of the original and compressed versions:

ls -l ~/project/sample_executable.sh
ls -l ~/project/sample_executable.sh.gz

Example output:

-rwxr-xr-x 1 labex labex 57 Apr 17 12:34 /home/labex/project/sample_executable.sh
-rwxr-xr-x 1 labex labex 37 Apr 17 12:34 /home/labex/project/sample_executable.sh.gz

As you can see, the compressed version is significantly smaller in size compared to the original executable file.

Now, let's try to execute the compressed file:

~/project/sample_executable.sh.gz

Example output:

This is a sample executable file.

The compressed file can be executed directly, without the need to decompress it first.

Decompress and Execute Compressed Executable Files

In this step, you will learn how to decompress and execute compressed executable files using the gzexe command.

First, let's verify the compressed executable file we created in the previous step:

ls -l ~/project/sample_executable.sh.gz

Example output:

-rwxr-xr-x 1 labex labex 37 Apr 17 12:34 /home/labex/project/sample_executable.sh.gz

To decompress the file, you can simply execute the compressed file, and it will automatically decompress and run the original executable:

~/project/sample_executable.sh.gz

Example output:

This is a sample executable file.

As you can see, the compressed file executed successfully and displayed the expected output.

Alternatively, you can also use the gunzip command to decompress the file:

gunzip ~/project/sample_executable.sh.gz

This will create the original sample_executable.sh file, which you can then execute directly:

~/project/sample_executable.sh

Example output:

This is a sample executable file.

The gunzip command can be used to decompress any file compressed with the gzip utility, including those compressed with gzexe.

Summary

In this lab, you first learned about the purpose and functionality of the gzexe command in Linux, which is used to compress executable files to save disk space. You then demonstrated how to compress an executable file using gzexe and verified the reduced file size. Finally, you learned how to decompress and execute the compressed executable file directly, without the need for decompression.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like