Self-extracting compressed files
Last modified on July 24, 2026 • 1 min read • 141 wordsToday I created a self-extracting, compressed file from a pdf document (disclosure.pdf).
Today I created a self-extracting, compressed file from a pdf document (disclosure.pdf). First I compressed the pdf file:
bzip2 disclosure.pdfThen I create a text file (header.txt) with the following content:
!/bin/sh
echo ""
echo "MyPackage v99.99 - extracting archive with bunzip2… please wait"
echo ""
SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`
#Take the archive portion of this file and pipe it to bunzip2
tail +$SKIP $0 | bunzip2 > disclosure.pdf
exit 0
__ARCHIVE_FOLLOWS__Then I concatenate both files (header.txt and disclosure.pdf.bzip2):
cat header.txt disclosure.pdf.bzip2 > disclosure.pdf.bzip2.shAfter this I just have to give the file execution privileges for everybody:
chmod a+x disclosure.pdf.bzip2.shTo uncompress the file, I just type:
./disclosure.pdf.bzip2.shOf course the bunzip2 program has to be installed on the system of the recipient of this file; one can easily replace the bzip2 algorithm by any other, e.g. tar.