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

  • Repair, decompress, restore data in corrupted rar archives, errors in 3 ways - 99% successRepair, decompress, restore data in corrupted rar archives, errors in 3 ways - 99% success
    instructions on how to fix corrupted .rar archives: repair rar archives with the built-in tool in winrar; by the option keep broken files or by recovery toolbox for rar software
  • How to automatically delete Zip files after extracting on MacHow to automatically delete Zip files after extracting on Mac
    there are many ways to reduce clutter and keep your mac neat. you can use powerful software like clean my mac, or take advantage of apple's existing features to keep your hard drive neat.
  • How to create a Live CD Linux discHow to create a Live CD Linux disc
    a live cd is a bootable cd, dvd or usb drive with an operating system ready to run when the disc is inserted into the computer. this article will show you how to create a linux live cd.
  • Create your own Linux distribution with Ubuntu ImagerCreate your own Linux distribution with Ubuntu Imager
    have you ever wanted to create your own linux distribution but don't know where to start? it's easier than you think. distroshare ubuntu imager creates a live iso that can be installed from an ubuntu or derivative distribution.
  • 8 easy tools to create your own Linux Distro8 easy tools to create your own Linux Distro
    you want to create your own distribution but don't know where to start and what tools to use, so read this article to learn about distro-creating tools yourself!
  • Create bootable USB with Linux Mint 19.3Create bootable USB with Linux Mint 19.3
    in today's article, tipsmake.com will show you how to upgrade from the latest linux mint 17.3 to the existing linux mint 19.3. here is a step by step guide to doing this!
  • How to create a Linux Bootable USB driveHow to create a Linux Bootable USB drive
    suppose you want to create usb bootable linux to boot and access on another computer but don't know how to do it. please refer to tipsmake's article below to learn how to create a linux bootable usb drive.
  • How to create SSH key on LinuxHow to create SSH key on Linux
    ssh keys allow you to keep your remote server accounts secure while providing password-free access. it's easy to generate an ssh key on linux.
  • How to create dual boot Linux and Windows 10 on LinuxHow to create dual boot Linux and Windows 10 on Linux
    many people think that creating dual boot is easy for operating systems like linux mint or ubuntu, where everything is handled in the installation tool. the fact that this setup can easily be implemented on most versions of the linux operating system on the market using a simple tool. you can create dual boot linux and windows 10 regardless of which linux operating system you are running.
  • How to quickly create new blank text files on Windows, Mac and LinuxHow to quickly create new blank text files on Windows, Mac and Linux
    text file is useful for everything. recording a note, storing information, and journaling are just a few of the many things you can do with text files. today, we will show you how to create new blank text files in windows, mac and linux quickly. in windows, it is easy to locate new text files. but on mac and linux, this job requires some initial setup, then creating a new text file is also quick and easy.