Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Create Self-extracting Archives with Shar in Linux

Learn how to Create Self-extracting Archives with clear steps, useful examples, and practical tips. Complete the task correctly and avoid common mistakes.

Table of Contents

This updated guide explains how to Create Self-extracting Archives with Shar in Linux through clear steps, practical examples, and important checks that help prevent common errors.

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 this guide!

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 may need 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.

Create Self-extracting Archives with Shar in Linux — Install Shar screenshot 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.

  • Of course, shar is the program.
  • ./* is the input, and in this particular case, it means all the files in the directory.
  • > 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>.
  • ./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).

Create Self-extracting Archives with Shar in Linux — Group Files screenshot 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.

Create Self-extracting Archives with Shar in Linux — Extract Shar Archive screenshot 3 Extract shar archive

FAQ

What is the easiest way to Create Self-extracting Archives with Shar in Linux?

Start with the requirements in this guide, then follow each step in order. Check the result after every major change so problems are easier to identify.

Can beginners follow these instructions?

Yes. The process is organized into practical steps, and you can repeat any step before moving forward.

What should I check if the method does not work?

Confirm your software or device version, permissions, settings, file format, and internet connection when the task depends on online services.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.