Search code examples
cygwinbzip2

How can I zip a file using Cygwin and bzip2?


I have downloaded Cygwin and the package to zip files (bzip2) but I cant figure out how to use its command to simply zip a file to another location.

All I want to do is something like:

bzip2 myfile somelocation

Solution

  • You want to use:

    bzip2 --keep [file to zip] > [Destination]
    

    Omit brackets when filling in the details.

    So, for your example, you would want to say:

    bzip2 --keep myfile > somelocation
    

    bzip2 writes to standard output, so you just need to use basic shell tools to direct or pipe this output to your destination. Your destination will be a file, not a folder, so if you want the compressed file to go inside a folder called somelocation, you would want to say something like

    bzip2 --keep myfile > somelocation/myfile.bz2
    

    The --keep parameter tells bzip2 not to delete your original file. If you do want to delete it, omit this parameter.

    I tested this with my own installation of Cygwin on Windows 8.1.