shar (Shell archive) file format
.shar · self-extracting shell script · introduced 1980 by Unix community
What is a shar (Shell archive) file?
A shell archive (shar) is a POSIX shell script that, when executed, recreates a directory tree using here-documents. shar archives were heavily used on USENET in the 1980s and 90s for distributing source code. They are dangerous today — running an untrusted .shar gives the author arbitrary code execution.
Most readers reach this page after double-clicking a .shar file and finding their operating system unsure what to do with it. The good news: shar (Shell archive) is a well-understood format with mature tooling on every major platform. It is supported in one click by mainstream archivers on Windows, macOS, and Linux.
How to extract a shar (Shell archive) file
Opening a .shar file is straightforward on every modern operating system. The exact steps depend on which platform you are on:
On Windows
- Locate the
.sharfile in File Explorer. - Right-click the file. If you have 7-Zip installed, choose 7-Zip → Extract Here. On Windows 11 the built-in extractor handles ZIP, 7z, RAR and several other formats directly through Extract All…
- If prompted, pick a destination folder and click Extract.
- The extracted files appear in a folder next to the original archive.
On macOS
- Find the
.sharfile in Finder. - Install The Unarchiver from the Mac App Store, or Keka for both creating and extracting.
- Right-click the file → Open With → The Unarchiver (or just double-click after Unarchiver is set as the default).
- The extracted folder appears next to the archive.
On Linux
- Use your file manager: right-click the archive → Extract Here (file-roller on GNOME, Ark on KDE).
- On the command line, run one of:
7z x archive.shar # works for almost any format
- The files appear in the current directory.
How to create a shar (Shell archive) file
To pack files into a .shar archive, you typically need an archiver that supports writing this format. Not every tool can create every format — for example, only WinRAR can create real RAR files. The sidebar lists the software known to read and write shar (Shell archive).
On the command line, the canonical create command is:
# Use 7-Zip, PeaZip, or the format's reference tool to create .shar files.
If you regularly create archives at scale, a dedicated archive automation suite can wrap this command in scheduled jobs, integrity checks, and offsite replication.
Strengths
- Trivial to read by hand
- No special tool required to extract — just run with sh
Weaknesses and limitations
- Arbitrary code execution risk
- Largely retired
Typical use cases
- USENET source distribution (historical)
- Vintage Unix archives
Technical details
shar (Shell archive) uses the POSIX shell + here-documents algorithm and is identified on disk by the magic byte sequence #!. The standard MIME type is application/x-shar. The format is an open specification and is free for any use.
Frequently asked questions
Is shar (Shell archive) safe to open?
Archive files are containers — they are only as safe as what they contain. A .shar from a trusted source is fine; one received from a stranger can hold malicious executables, scripts, or files engineered to exploit bugs in your archiver. Always keep your archiver updated, and never run unknown executables that come out of an archive. A safe workflow is to extract into a sandbox and scan the contents before opening anything.
What is the maximum file size?
Modern implementations support archives in the multi-terabyte range. The practical limit is your filesystem (FAT32 caps at 4 GB; ext4, NTFS, APFS, and exFAT all comfortably handle multi-TB files).
Can I password-protect a shar (Shell archive)?
Some archivers can wrap shar (Shell archive) files in an encrypted container, but the format itself does not always include built-in encryption. Check your archiver's documentation.
How does shar (Shell archive) compare to other formats?
See our format comparison pages such as ZIP vs 7z, ZIP vs RAR, and tar.gz vs tar.xz for side-by-side feature tables.