Self-Extracting Archives for Linux

This topic was published by and viewed 2445 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author

  • DevynCJohnson
    • Topics - 437
    • @devyncjohnson

    Many Windows users are familiar with self-extracting archives. These are special archives that do not depend on any software on the current system for extraction. This allows developers to place many files into a single archive (with or without compression). The user can then obtain the single file and open it without needing to install an application to open the archive. Self-extracting archives can be used to distribute files, make an installer, or store a stand-alone executable and its libraries in on file. However, does Linux have any kind of self-extracting archive or a need for it?

    Self-extracting archives are available for Linux, and Linux has a use for this feature. For instance, Python developers may use Cxfreeze to create a stand-alone executable. However, many library files are in the directory with the stand-alone executable. With the use of a self-extracting archive, the developers can distribute a single executable file that already contains all of the needed libraries. Then, users would execute the single file without needing any additional software.

    As another example, assume a developer makes a single program that is composed of multiple shell scripts. With a self-extracting archive, the many scripts can appear as one, thus making the program less confusing to use.


    "makeself" is a utility that creates self-extracting archives. Developers would need to obtain makeself to create the archive, but users do not need any software. The user only needs to execute the archive to run the contained program or execute the archive to cause the contained files to be extracted. For developer/packager usage, run a command in this format "makeself [options] DIR NEW-FILENAME LABEL STARTUP [args]".

    • [options] - place parameters for makeself here
    • DIR - the name and path of the directory containing the files to place in the archive
    • NEW-FILENAME - the desired name for the self-extracting archive
    • LABEL - message displayed in a terminal when the archive is decompressed
    • STARTUP - if this archive contains a program/script, specify the executable file that is to be run
    • [args] - commands to run after the extraction

    For illustration, after writing a program, the developer can package it by running [code]makeself --nox11 --noprogress --nowait ./ezv-fstab/ ./ "Loading ezv-fstab" ./etc-fstab[/code]

    The parameters make the extraction remain quiet and independent of the user's input (after the user executes the archive). "./ezv-fstab/" indicates the folder to package is in the current directory. "./" is the name of the archive to create. The message is in quotes, and after that, the developer specifies the executable to run when executing the archive. The path is relative to the archive. So, "./etc-fstab" is in the top-level of the archive and is the executable that will be run when the archive is executed.

    Other parameters exist for makeself, but the ones used above are likely to be used by most developers. View the manpages or documentation for more info.

    To obtain "makeself", search your repositories/package-manager, go to (, or run " wget ". To install makeself by obtaining it using the former method, run the following code -

    chmod 755
    cd makeself-2.1.5
    cp *.sh /usr/bin


    "shar" is a shell script archive. This archive is only used for file storage and distribution. To use shar, type "[code]shar ./* > ../FILE.shar[/code]" to archive all files in the current directory and save the shar-file in the directory above. Various parameters can be applied to shar to change the results of the created archive.

    Various parameters can be applied when creating or extracting the archive. For instance, "-x" can be used during creation to inform the archive that when it extracts its contents existing files should be overwritten. Then, when a user obtains the shar archive and extracts it, any files with the same name as the archive's contents will be overwritten. This is useful for applying patches.

    Shar archives can be used to "install" local programs or files. A developer could make a game that users can install locally in their Home folder. Then, updates and patches can be applied by extracting the newer shar into the game's directory. This is an example of a use for the "-x" parameter.

    When creating a shar archive, the "-s" parameter can be used to specify the creator of the archive. For example, "[code]shar -x -s [email protected] *.pdf > manual.shar[/code]" will create an archive that contains metadata specifying the person (or company) that packaged the archive. By default, when not explicitly using this option, the current system value will be used (USER@HOSTNAME).

    The "-L" parameter allows users to specify the size at which the archive will split. For instance, "[code]shar -L 5000000 *.LARGE-FILES > large.shar[/code]" will create an archive. Once the archive reaches five megabytes (5MB), then another archive will be made. Each created archive will be no larger than the specified value. When declaring the max archive size, type the value as bytes.

    The "-l" (lowercase "L") parameter is the same as "-L". However, files will not be split. Thus, if the user specifies that the max size is 2MB (-l 2000000), then some archives may still exceed that limit. To explain, if an archive is 1.5MB and then the next file to add to the archive is 1MB, shar will not split the 1MB file, but will add the whole file to the archive. As a result, the archive is now 2.5MB.

    Various parameters are also available to compress the archive. Without compression, the shar is a plain-text file containing the files (that are archived) and code (that provides the self-extracting features). With compression, the archive's code is still readable, but the files appear as random sequences of characters. Shar archives can be emailed to users as plain text. Copy the contents of a shar file into the body of an email. Then, the recipient can copy the email's body and paste the contents into a plain-text file.

    To extract the files, execute the shar file. Users may need to give it executable permissions by running chmod +x ./FILE.shar. Alternately, type "sh FILE.shar" to extract the shar archive without giving the file executable permissions.

    There is an "unshar" command, although it seems useless to have a program that uncompresses a "self-extracting archive".

    shar is a common GNU utility that can usually be obtained from the system's standard software-sources/repositories.


    Remember that self-extracting archives are executables that require executable permissions. Only execute a self-extracting archive from a trusted source. Otherwise, the system could suffer from malware, data-loss, and other security threats.

    Sample shar Contents

Viewing 1 post (of 1 total)