unshar - Linux


unshar is a command-line utility used for unpacking shell archives (shar files) back into the original files. Shar files are primarily used to bundle multiple files or directories into a single file, often for easier distribution or backup. The unshar command takes these archives and extracts the files contained inside them. It is most effective when working with archives created by the shell archiving utility (shar) and is commonly used in environments where traditional archiving tools like tar and zip may not be available.


The basic syntax for unshar is as follows:

unshar [options] [file ...]
  • [file …]: One or more shell archive files to unpack. If no files are specified, unshar reads from the standard input.


unshar includes several options that control its behavior:

  • -c: Checks whether the unpacking of the archive will succeed but does not actually write the files.
  • -d: Debug mode. Prints out detailed debugging information.
  • -f: Forces the overwriting of existing files without asking.
  • -x: Skips the confirmation check before extracting each script from the archive.
  • -e: Stop execution upon error.
  • -C [directory]: Changes to directory before unpacking. Useful for extracting files directly into a specific folder.

The default behavior is to prompt for overwriting existing files and to stop upon encountering an error.


  1. Extracting a shar file to the current directory:

    unshar archive.shar
  2. Extracting multiple shar files without user interaction:

    unshar -x project1.shar project2.shar
  3. Checking extraction, verbose mode:

    unshar -c -d setup.shar
  4. Extracting files into a specific directory:

    unshar -C /path/to/destination newpackage.shar

Common Issues

  • Overwriting Files: Users may run into issues with files being overwritten without prompt if -x is mistakenly used. Carefully use -f to force overwrite if necessary.
  • Permission Errors: Running unshar without appropriate permissions in the target directory may cause errors. Ensure proper permissions or run under sudo if needed.


unshar can be seamlessly integrated into shell scripts and combined with other commands for batch processing or part of a larger sysadmin workflow:

for file in *.shar; do
    unshar -f "${file}" -C /path/to/extract

This script loops through all .shar files in the current directory, extracting them into a specified path.

  • shar: Create shell archives.
  • tar: Archiving utility with more features but more overhead.
  • gzip, bzip2: Compression tools often used in conjunction with shar.

For further reading and more detailed information, referring to the man pages can be helpful (man unshar, man shar).