7-zip unavailable in 64-bit Cygwin

At the time of this writing, 7-zip was still not available in 64-bit Cygwin.
Here’s how to work around this issue by using the Windows 7z.exe from Cygwin. NOTE: This method will not show percent complete (no progress report).

1) install the 64-bit 7zip for Windows from http://www.7-zip.org/
2) in Cygwin, type nano ~/.bashrc and at the bottom, paste in the line:
alias 7z="/cygdrive/c/Program\ Files/7-Zip/7z.exe"
3) close and reopen Cygwin and you’ll find that you can 7-zip files as usual.

Example usage:
say you have a big file named huge.dat. To archive this file type:
7z a huge.7z huge.dat

to extract the file type
7z e huge.7z

7zipping and moving recursively by top-level directory

The following script takes the top-level directories and makes a 7zip archive from each top-level directory, containing all its subdirectories.

This function has a primitive “no-clobber” that won’t overwrite existing files.

Note that you can use up all HDD space if you have a lot of huge files — watch the progress of the program. You assume all risks for using this script.


#!/bin/bash
# Michael Hirsch 2013
# BSD license
# 7zip's and moves files per directory

: ${2?example: 7z_mv ~/inDir /media/outDir}

MainDir=$1
OutDir=$2

#check if OutDir directory already exists
ArcOutDir=$OutDir/$MainDir #not for use inside tar command
if [ ! -d $ArcOutDir ]; then
echo creating $ArcOutDir
mkdir $ArcOutDir
fi

#list ONLY 1st level subdirectories
DirList=($(find "$MainDir" -maxdepth 1 -mindepth 1 -type d | sort))
echo Found directories: ${DirList[@]}
#exit
nDir=${#DirList[@]}
nDir1=$(($nDir - 1))

#main loop
for i in $(seq 0 1 $nDir1); do
currDirIn="${DirList[$i]}"
currArcOut="$OutDir/${DirList[$i]}.7z"

###################
# no clobber
if [ -a $currArcOut ]; then
echo "Skipping directory $currDirIn since $currArcOut already exists"
continue #skips to top of for loop
fi
####################

echo "7zipping and moving $currDirIn to $currArcOut"

# don't use the -o option, it doesn't seem to work right
7za a -t7z -mx=3 -mmt=on -m0=lzma2 "$currArcOut" "$currDirIn"

done