How to create self-extracting archives with shar in Linux

It's annoying, even tiring, to explain to someone how to unzip after you send them an archive. If so then you will definitely love shar in Linux.

With shar, you can 'bundle' multiple files together. If you send it to someone, they just need to make sure it is executable and run to extract it. No need for complex commands or instructions during the process.

Let's see how you can use shar to group files through the following article!

Install shar

Shar is not included in most Linux distributions by default, so you will have to install it first in order to create Shar file archives automatically extracted. However, you won't find it in Software Center or via apt. Instead, you will have to install larger sharutils packages that contain shar. To do that, activate Terminal and use the command:

 sudo apt install sharutils 

Shar is a command line tool and works on multiple files at once, putting them into a single archive. Therefore, for convenience and ease of use, create a temporary directory and move or copy all the files you want to put into the shar archive to that temporary directory.

With the Terminal still active, use the cd command to move the file into the newly created directory.

How to create self-extracting archives with shar in Linux Picture 1 Use the cd command to move the file into the newly created directory

Group files

To create a shar archive, run the following command:

 shar ./* > ./archive-filename.shar 

Change archive-filename to the preferred file name.

Feel free to dig deeper to understand how you can use your files.

  1. Of course, shar is the program.
  2. ./* is the input, and in this particular case, it means all the files in the directory.
  3. > separates the input and the output of the command. The program understands it as follows: Take all the input on the left of the> and combine it into a single file identified on the right of the>.
  4. ./archive-filename.shar is the path and name of the output file. You can change it to whatever you want.

This process is quite fast and usually does not take more than a few seconds (depending on PC performance).

How to create self-extracting archives with shar in Linux Picture 2 Group files

Once you've created the archive, you can share your new files with others. Although they will also need sharutils installed to automatically extract operations, as you will see in the next step, things will be simpler than dealing with regular repositories.

Extract shar archive

When the other person receives the shar repository, all they need to do is make it workable, then run it.

Assuming the other person has sharutils installed, they can extract the archive using the following commands:

 chmod +x archive.shar ./archive.shar 

The files contained therein are extracted right next to, in the same directory.

How to create self-extracting archives with shar in Linux Picture 3 Extract shar archive
5 ★ | 2 Vote

May be interested

  • 5 best open source backup utilities for LinuxPhoto of 5 best open source backup utilities for Linux
    there are so many backup utilities available in the market, confusing you to choose the best one out of the many options. this article will help you choose the free backup utility that is best suited for linux and suits your needs.
  • How to set the JAVA_HOME path in Debian 10Photo of How to set the JAVA_HOME path in Debian 10
    in this article, we will learn how to install java jdk on the debian operating system and then set the java_home and path variables.
  • How to install Microsoft Teams on LinuxPhoto of How to install Microsoft Teams on Linux
    if your job requires using a linux distribution such as ubuntu, debian or red hat, you no longer need to use a windows 10 device to connect with colleagues, as microsoft teams is now available on linux. .
  • How to install dictionaries in Linux TerminalPhoto of How to install dictionaries in Linux Terminal
    a locally stored dictionary utility can really be useful when no other dictionary is available. there are many options in the linux software world. among these, there is an option that runs fairly 'smoothly' from the system terminal, called sdcv.
  • How to change the cursor size on the Debian 10 desktopPhoto of How to change the cursor size on the Debian 10 desktop
    debian allows you to change the cursor size via the settings utility. you can access the settings utility through the application launcher search.
  • How to spell check in Linux TerminalPhoto of How to spell check in Linux Terminal
    linux also has a command line spell checker utility in terminal. the utility is called aspell and is installed by default on ubuntu. this is how you can use aspell to check spelling in a terminal.