What is MIME type "application/x-shar"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

application/x-shar is a MIME type for shell archive files. These files are plain text and contain shell commands that recreate a collection of files when executed.

Such files typically use the file extension SHAR.

For more details on shell archives, visit Wikipedia.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: application/x-shar    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="application/x-shar">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'application/x-shar');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

How do I extract a file with the application/x-shar MIME type?

Since these are self-extracting shell scripts, you typically extract them on Unix-like systems (Linux, macOS) by running the command sh filename.shar in a terminal. On Windows, you can view the content with a text editor, but you will need a compatibility layer like WSL or Cygwin to execute the extraction logic.

Are application/x-shar files safe to run?

You should treat them with caution. Because a .shar file is an executable shell script, it has the power to run arbitrary commands on your system. It is best practice to inspect the file in a text editor to verify the code before executing it, ensuring it does not contain malicious commands.

How do I configure Apache to serve .shar files correctly?

To ensure browsers recognize the file correctly, add the directive AddType application/x-shar .shar to your .htaccess file or main server configuration. This tells the server to send the correct headers, preventing the browser from treating it as a generic text file.

Why does my browser display the SHAR file code instead of downloading it?

This happens if the web server identifies the file as text/plain rather than application/x-shar. To fix this, you can configure the server to send the correct MIME type or force a download using the Content-Disposition: attachment header.

What is the difference between application/x-shar and application/x-tar?

A SHAR file is a text-based shell script that extracts itself when run, making it easy to share via email or text protocols. A TAR file (served as application/x-tar) is a binary archive format that requires a specific utility (like the tar command) to extract and is generally better suited for binary data.

Does Nginx support application/x-shar by default?

Nginx usually relies on a mime.types file to map extensions. You should check this file and ensure the line application/x-shar shar; exists. If not, add it to your configuration block to ensure correct handling of SHAR files.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.