With shar, you can “pack” many files into a single one. If you send it to a contact of yours, they’ll just have to make sure it’s executable and run it to extract it. There is no complicated commands and no need to guide them through the process. Let’s see how you can use it to pack a group of files into a single “shar” file.
Install Shar
Shar is not included in most Linux distro by default, so you will have to install it first to be able to create auto-extracting Shar file archives. You won’t find it in the Software Center, though, nor on its own through apt. Instead, you will have to install the larger “sharutils” package that contains it. To do that, fire up your terminal and use the command:
Find and Prepare Your Files
Shar is a command-line tool and acts on a bunch of files at once, placing them in a single archive. Thus, for convenience and ease of use, create a temporary folder and move or copy all the files you’d like to include in a shar archive to the temporary folder. With your terminal still active, cd to your newly-made directory.
Pack Your Files
To create your shar archive, run the following command: Change the “archive-filename” to your preferred filename. Let’s “disassemble” this to make sense of how you can use it for your files.
The shar at the very beginning is, of course, the program itself.The ./* is the input, and in this specific case, it means “all the files in the directory we are into.”> is the splitter between the input and the output of the command. The program understands it as “take every input on the left of the bracket and combine it into the single file defined on the right of the bracket.”../archive-filename.shar is the path and the name of the output file. You can change it to anything you wish.
The process is quite fast and usually doesn’t take more than seconds (depending on your PC’s performance). Once you have created the archive, you can share your new file with your contacts. Although they, too, will need to install sharutils for the auto-extraction to work, as you will see in the next step that everything will be simpler than dealing with typical archives.
Extracting the shar Archive
When your friend receives the shar archive, all they need to do is make it executable and then run it. Assuming your friend already has sharutils installed, they can extract the archive with the following commands: And that was it – the files it contained were extracted right next to it in the same folder. We cam now remove the original file they sent us. Most Linux desktops provide comprehensive support for compression formats like tar, gz, zip, etc., so shar is not very useful in this case. However, if you are using Linux in a server (or headless) environment, shar will be very useful, as you can easily extract an archive without having to remember the various commands – there are no extra steps, no flags and switches, and no other programs to install. In addition to shar, Windows, macOS and Linux all come with a native app to create self-extracting archive. Check it out!